Select an option when a value comes preloaded

I have a form B with three fields that appears when I clicked the "send" button from another form A.

a!formLayout(
label: "Form",
contents: {
a!textField(
label: "City",
labelPosition: "ABOVE",
saveInto: {},
refreshAfter: "UNFOCUS",
validations: {}
),
a!textField(
label: "Office",
labelPosition: "ABOVE",
readOnly: true,
refreshAfter: "UNFOCUS",
validations: {},
value: rule!CPRO_ER_getOffice(),
saveInto: {
a!save(ri!new.officeC,rule!CPRO_ER_getOffice())
}
),
a!radioButtonField(
label: "Type",
labelposition: "ABOVE",
choiceLabels: {
"car",
"red",
"urgency"
},
choiceValues: {
"car",
"red",
"urgency"
},
value: {},
saveInto: {},
required: true

),
},
buttons: a!buttonLayout(
primaryButtons: {
a!buttonWidget(
label: "Submit",
submit: true,
style: "PRIMARY"
)
}
)
)

the value of the first field "city" is written by hand.
the value of the second field "office" can:
- Empty if it has been sent from the previous form
-be preloaded -> I want that when it comes preloaded directly select "urgency" from the "radiobutton".
                 If it comes empty, then you can choose any of the three options.

Thanks!


  Discussion posts and replies are publicly visible

  • 0
    Certified Associate Developer

    Hello Alastr,

    On form A, You can create one local variable say "radioChoice". Now suppose if user enters something inside "office" field during that time you can populate the value for local!radioChoice to "Urgency".

    Now pass the value to form B and use this variable inside value and saveinto parameter of radio control.

    Sample code is as below

    Form A

    load(

    local!radioChoice,

    local!office,

    a!textfield(

    label:"Office",

    value:local!office,

    saveinto:{

    local!office,

    a!save(

    local!radioChoice,

    if(

    and(

    not(isnull(save!value)),

    len(save!vaue)>0

    ),

    "Urgency",

    null

    )

    }

    )

    Pass this local!radioButton Parameter to form B and the code on form B be something like

    Form B

    a!radiobutton(

    label:"Type",

    choiceLabels: {
    "car",
    "red",
    "urgency"
    },
    choiceValues: {
    "car",
    "red",
    "urgency"
    },


    value:ri!radioChoice, //Parameter that was passed from form A
    saveinto: ri!radioChoice

    )

  • thanks for answering but now I have another question
    I have a "new" form with two fields.
    The first "proposed" field is an entire field.
    The second "type" field is radiobutton with three options: "car", "model" and "urgent".
    When I enter the form the first field is loaded with a random number and I can choose an option of the second field.
    But now I want that when you enter the form and the random number is loaded, you select only the "urgent" option

    load(
    local!random: tointeger(split(tostring(rand()), ".")[2]),
    {
    a!integerField(
    label: "PROPOSED",
    labelPosition: "ADJACENT",
    value: local!random,
    saveInto: {},
    refreshAfter: "UNFOCUS",
    readonly: true,
    validations: {}
    ),
    a!radioButtonField(
    label: "Type",
    labelposition: "ABOVE",
    choiceLabels: {
    "car",
    "model",
    "urgency"
    },
    choiceValues: {
    "car",
    "model",
    "urgency"
    },
    value: ri!new.typeS,
    saveInto: ri!new.typeS,
    required: true
    )

    }
    )
  • 0
    Certified Associate Developer
    in reply to Alastr

    I modified your code to fulfill your requirement. Kindly check once

    load(
    local!random: tointeger(
    split(
    tostring(
    rand()
    ),
    "."
    )[2]
    ),
    local!new,
    local!choiceOption:if(
    and(
    not(isnull(local!random)),
    len(local!random)>0
    ),
    {"urgency"},
    {"car","model","urgency"}
    ),

    {
    a!integerField(
    label: "PROPOSED",
    labelPosition: "ADJACENT",
    value: local!random,
    saveInto: {},
    refreshAfter: "UNFOCUS",
    readonly: true,
    validations: {}
    ),
    a!radioButtonField(
    label: "Type",
    labelposition: "ABOVE",
    choiceLabels: local!choiceOption,
    choiceValues: local!choiceOption,
    value: local!new,
    saveInto: local!new,
    required: true
    )
    }
    )

  • entering the code I get the result so

    and what I want is like this
    that when loading the form the random number and already selected urgency come...
     
  • +1
    Certified Associate Developer
    in reply to Alastr

    What about this?

    load(
    local!random: tointeger(
    split(
    tostring(
    rand()
    ),
    "."
    )[2]
    ),

    /*local!random:null,*/
    local!selectedValue:if(
    and(
    not(isnull(local!random)),
    len(local!random)>0
    ),
    {"urgency"},
    null
    ),

    {
    a!integerField(
    label: "PROPOSED",
    labelPosition: "ADJACENT",
    value: local!random,
    saveInto: {},
    refreshAfter: "UNFOCUS",
    readonly: true,
    validations: {}
    ),
    a!radioButtonField(
    label: "Type",
    labelposition: "ABOVE",
    choiceLabels: {"car","model","urgency"},
    choiceValues: {"car","model","urgency"},
    value: local!selectedValue,
    saveInto: local!selectedValue,
    required: true
    )
    }
    )

  • Thank you so much for help me. He helped me totally for what I wanted to do