In this post, I’m going to show you how to get Picker control’s SmartObject value correctly.
Get Picker Control’s SmartObject Value Correctly
When K2 smartforms Picker control executes the “On Changed” event, you will be able to extract the selected item’s values via the underlying SmartObject properties.
It is a great way of populating the form data with more information regarding the selected item and you do not need to execute another SmartObject to do so as well (Yeah! No extra trips!). So in my case, my form allows the user to select the staff and display their relevant information.
Do Not Remove the View Initialise Rule!
Why? It is the “good practice” to remove empty “View Initialise” rules from the “Form Initialising” rule. This is to avoid executing unnecessary actions on the client browser. If you look at my demo View here, there’s no Initialising rule.
So naturally, my first reaction will be to remove the “View initialise” rule in my “Form Initialising” Rule. By the way, if you are wondering why it was there in the first place, K2 smartforms automatically adds the event to the “Form Initialising” rule when you add a new View to the Form.
With the View Initialise rule removed, I tested the Form but the fields did not get populated.
But if I try to search for another User Id, it populates correctly this time!
If you refresh the Form and try again, you will get the exact same behaviour. The Picker always fails on the first execution. Why?
- Multiple records inserted with RuntimeListViewRowCount option - 30 May 2017
- Friendly Error Message on K2 smartforms - 04 May 2017
- Add company logo and change K2 login form descriptions - 02 Aug 2016