Get Picker Control’s SmartObject Value Correctly
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?
Well, simple enough reason is that the “View Initialise” rule somehow helps setup the JavaScript events on the browser end, so it is crucial that the Picker controls get initialised first before use. So go on and put back the “View Initialise” rule and everything will be good to go.
Have Fun!
- 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