Using a custom renderer to conditionally set a picklist's value?

Hi Jonathan,

When you send a particular value into one of Skuid’s field renderers, this will only affect the UI, the models in the background will not be affected.  One approach that would work (probably the wrong one) would be to use Skuid’s updateRow API to change the value of the field and then render it.  You could add this code inside the first block of your if statement and it would work.

var accModel = skuid.model.getModel('Account'); accModel.updateRow(acc,'Type','Individual'); 

While doing this probably wouldn’t cause any issues in your scenario, I would say that it really isn’t a best practice to be giving your custom field renderers “side effects” like this.  In the course of running your Skuid page, this renderer could be run many times.  In my opinion, the act of rendering a field should not affect the underlying models.

Another approach you could take would be to create an inline resource that simply adjusted the models right after page load.  Then your custom field renderer could still determine read/edit mode when it ran, but would not be responsible for setting values in your models.

Your inline resource would look something like this…

(function(skuid){ var $ = skuid.$; // Wait for the page to load before performing this action.<br> $(function(){<br> var accModel = skuid.model.getModel('Account'); var accRow = accModel.getFirstRow(); if (accRow.Type !== 'Group Coordinator') { accModel.updateRow(accRow,'Type','Individual'); }<br><br> });<br>})(skuid);