Making a field enabled or disabled can be a very easy process and can be done in different ways. One way you can do it is with business rules but sometimes what you’re trying to do can be too complex for a business rule. For example if you need to disable a field based on the results of a entity schema query, you can’t do that with a business rule. Another way is you can enable or disable fields programmatically. In this article I’ll walk you through the steps to do so.
The steps for enabling or disabling fields programmatically are:
- Add a boolean attribute to the page
- Bind the attribute to the enabled property of the field in the diff
- Set the attribute as true or false to enable or disable the field on the page
When you add your boolean attribute to your page it will look something like this:
The value is what you want to have the default value be.
When binding your attribute to your field the code will look like this:
Notice the enabled property is bound to our attribute.
Now to enable or disable the field you have to set the attribute to true or false in the same way you would set anything on the page using this.set.
The point is you can’t directly change things that are in the diff. Instead you bind things in the diff to an attribute and then just change the attribute.