Editing Form Fields
If you're following along, you might've noticed by now that each attribute of your request object is automatically turned into a form field when you click the "Form" button in the Rulebricks editor, and each attribute in your response object is automatically turned into a result field, i.e. a field that will be displayed to the user after they submit the form.
This is a powerful feature that allows you to quickly create forms that collect the data you need, and display the results you want, without having to write any code.
But how do you customize these form fields? What if you want to change the type of a field, or add a description, or make a field required?
Sometimes, this behavior can be really important, for example if you want to collect text from a user, but you want to make sure they enter one of a few specific options, like "A" or "B". In this case, you might want to change the field type from "Short Text" to "Multiple Choice", and add the options "A" and "B".
Edit Fields
Let's walk through how to do this.
Open the form editor
First, open the rule you want to edit in the Rulebricks editor, and click the "Form" button in the top right corner of the rule editor to open the form editor.
View the form fields
The form editor has three tabs: "Form", "Edit Fields", and "Edit Results". Click on the "Edit Fields" tab to view and edit the form fields.
You should be able to see a dropdown for each field named "Input Variant", describing the particular type of field it is.
Note that by default, Rulebricks will automatically choose the field type based on the data type of the attribute in your request object. For example, if the attribute is a number, Rulebricks will choose the "Number" field type. Not all field types are available for all data types, and there are some cases where you may not be able to change the field type.
Edit the field
To change the field type, click on the dropdown and select the field type you want. You can also add a description, make the field required, or add options for certain field types.
In this brief example, we're changing the field type from "Short Text" to "Multiple Choice", and adding a few options.
Return to your form
Now, click the "Form" tab to return to the form editor, and you should see your changes reflected in the form. In this particular case, what used to be an open-ended text field is now a multiple choice field with specific options I compare against in my rule.
Edit Results
You can also edit the results fields in the same way, but instead of changing how inputs appear to the user, you're changing how results appear to the user after they submit the form.
These are useful for displaying the results of your rule in a way that makes visual sense to the user, and are purely for display purposes.
View the form results
To edit the results fields, click on the "Edit Results" tab in the form editor, and check out the "Display Variant" dropdown for each field.
Edit the display variant
Let's say in this particular case, simply showing the user "Income Verification: true" isn't very helpful, even though it's the result of my rule.
Instead, we can change the display variant to "Outcomes", which will show the user a more human-readable version of the result, like "Income Verified", depending on whether this particular result in the response data is true or false.
Return to your form
Now, when I head back to my form and try it out, I can see the results of my rule displayed in a way that makes sense to me and my users.