Formatting Rule
Formatting Rules are associated with controls rather than fields. In case we need to format the color of a textbox based on a condition this rule is the appropriate one.
In this scenario we are adding a field named Age. If the Age is greater than 100, the textbox should turn red in color. Let us do it.
Remove the previous field from the form and add a new field named Age. Set the type of field to Number as shown below:
Now drag the field to our form:
Once the form is ready, select the Age Textbox and from the ribbon menu choose menu item Add Rule > Is Greater than > Bad:
You will get the following dialog to capture the Max value.
Enter 100 as the value and click the OK button.
Good! Now you are read with the Formatting Rule. Save & Publish the form and inside SharePoint try to add a value greater than 100.
You will see that the color is changed to red.
Actions
Now we can try with the Action. Actions allow the following:
- Query Data from other Source
- Set another Field Value
- Submit the Form
- Get Data from a Web Part
Please note that there could be more than one action associated with a field.
Our scenario is to have 2 fields:
- Country of type text
- Currency of type text
When the Country name is India, the Currency must be set to Rupees.
When the Country name is America, the Currency must be set to Dollars.
Let us see how to make this work.
Now you can remove the previous fields, and add the above 2 fields.
Now click on the Country field and from the ribbon choose Manage Rules. In the Rule pane that appears, click the New Action button.
A new Rule will be created. Now click on the Condition link:
A new dialog will appear. Enter the detail as shown below:
So this adds our first condition, when the country field is equal to India. Now we have to set the Action for it.
Click on the Add button from the Rules pane and choose Set a field's value. In the dialog that appears, choose the field Currency and set the value to Rupee:
Now you have added the condition and action for Rule 1.
Similarly you can add one more rule; check for the Country America and set the Currency field to Dollar.
Now Save & Publish the form. Inside SharePoint try entering India and press the tab button. You will see that the Currency field is set to Rupee.