top of page

Moji5 Knowledgebase

Dynamically making a field compulsory

Problem

You have a Customer form with 2 fields:

  • Customer Type (a radiobutton list containing "Government", "Private" and "Others")

  • Other type (text field)


You want to make it so that when "Others" is chosen for "Customer Type", the "Other type" field will become compulsory. If anything else is chosen, the field will not be compulsory.



Solution

Setting up the sample:

1. Create a new form called "Sample Customer Type".

2. Create two fields:

  • Customer Type (radiobutton)

    Fill the textbox then click Add to add the item into radiobutton selection.

    Click Save changes.


  • Other Type (Singleline Text field)


3. You should now have the screen shown below:



Solution:

1. Click on "Edit form behavior"

2. Create a new behavior, and click on "Action Wizard".


2. Create a new behavior, and click on "Conditional Action Wizard".


3. In the "Behavior" section, click the "Create an action" button.


4. Choose the "Set compulsory fields" icon (highlighted below).


5. Set the "Other type" field to "Yes" and click "OK".


6. Click "Save changes".


7. Click "Create now".

8. Create another new behavior. Click "Conditional Action Wizard".


9. Create the condition "Customer Type". "Value" = "Other" as shown below.


10. Click on the "<< Add" button to add it to the list box on the left.


11. Add it one more time to the list box on the far left.


12. In the "Else Behavior" section, click on "Create an action".


13. Choose the same "Set Compulsory fields" action, and in the next page, set "Other Type" to "No".


14. Click OK, then click the "Save changes" button and then create the behavior.

15. Click "Create now".


16. The last step is to activate the postback for "Customer Type", so that each time you change the selection in "Customer Type", it would refresh the form. To do this, go back to the form design.

17. Click on the Advanced settings icon next to the "Customer Type" field, and

change "Auto Postback" from "No" to "Yes".


18. Save your changes, then publish and run the form.


Testing your Solution:

1. When you select the "Other" option, an asterisk appears next to the "Other Type" field, indicating that it has become compulsory. When you try to save the record without keying in anything in the "Other type" field, an error message such as the following will appear:



2. When you switch the customer type to anything else, the asterisk disappears, and the field is no longer compulsory.

Comentários


bottom of page