Introduction
Being able to give rules names has created something new and wonderful. Well, it has for me, and even now, sitting in Pret having breakfast and writing this, I’m still thinking about how great it is. So what is this wonderful thing, you may be asking?
It’s the ability to have a rule on a view that isn’t related to any event, like a button click or a drop-down list changing. These rules aren’t bound to any event on the view. They have become unbound.
First, let’s look at how easy it is.
Building a view with unbound rules
To build a view with unbound rules, go through the following steps.
- Create a view as normal. In this case I’m creating a view bound to a SmartBox SmartObject called ‘Customer Details’.
- Don’t add a button assigned to a method. Just add the fields you want.
- Click on ‘Rules’, but instead of clicking on an event like you normally would, click on ‘Rule Name’ and enter the name ‘Unbound Save Data’.
- Click on Conditions, select ‘View Passes Validation’ and choose which fields are required.
- Click on Actions and select the view method ‘Create’.
- You can add more actions if you want to, such as showing a message, or showing an error message if the view isn’t valid.
- Click ‘OK’ and then ‘Finish’.
This is a very simple unbound rule, but you could build much more complicated rules if you wanted to.
Using the view with the power of unbound
Now that we’ve created a view with unbound rules, how do we put those rules into action? By adding the view to a form.
- Create a new form as normal.
- Drag the newly created view onto the form, along with any other views you want.
- Add a new button to the form.
- Click on ‘Rules’.
- Select ‘When a form control raises an event’ from the Events tab.
- Select the button using the control link on the rule.
- Click on the Actions tab, search for ‘Execute a rule’ and select the ‘Unbound Save Data’ rule.
- You’re now ready to test the rule.
The original post had a video going through the full example with some extra rules.
Conclusion
Views can be built to handle all the complex rules, then dragged onto any form, and the form decides when to fire those rules. That leaves the form developer to literally drag and drop without worrying about complex business rules on the form. It also makes standards easier to follow, because we can keep a library of views with all their rules predefined that just need to be called, in the same way a developer would call methods in a library.
To me this opens up a new way of building applications. Instead of making views dumb containers, or having rules bound to a hidden button on the view, we can now create really intelligent views. No, we can create SmartViews.