Skip to main content

Long Problem Short: Is there any way to prevent rendering all the related fields on model.save()? Why??? I have a skuid page with pretty much all custom renders. I’m using the fact that registerSnippet gets called when a custom field is rendered to execute some business logic. For this example, I want to render a field only if another field has data. I also want the value of the rendered field to be a result from a callout. Example Code:


skuid.snippet.registerSnippet('RenderConditionalField', function(args) { var tModel = skuid.model.getModel('myModel'); var dependantField = tModel.getFirstRow().myField__c; if(dependantField){ MyController.getSomeValue(dependantField,function(){ //call function to render the field, pass in the value helpers.components.customPicklistRenderer(args, 'conditionalField__c', result); }); } }); 

This works great, except for a side effect of a poor design choice. These fields are all attached to my primary model. At the end of the business process, I save a couple fields to this model. Looks like this calls the render function on all the fields related to the model, which in turn executes my custom render snippets. The conditional statements in my snippets at the point have all been met, causing some undesired effect (some webservice callouts execute). I’m kinda hoping there is something in the undocumented model.save: options object that might be what I’m looking for. If not, I can probably just move all my custom fields to a dummy Model that has no interaction with the BL. Just wanted to check before begin refactoring.

There aren’t any “don’t notify editors / lists / fields” properties on the save options object, so that’s not going to work. However there’s another approach that might work. There are 4 different kinds of structured objects that can be “registered” on Skuid Models: -skuid.ui.Editor -skuid.ui.List -skuid.ui.Item -skuid.ui.Field Both Tables and Field Editors internally leverage skuid.ui.List (again not documented), and since List is higher-level than Item or Field, un-registering a List will stop a Model from telling that List to rebuild itself after a save. So the strategy is: immediately pre-save, unregister your Table / Field Editor’s underlying List from the Model. In the after save callback, re-register the Lists on the Model. For both Tables and Field Editors, you can access their internal List like so:


var myTable = skuid.$('#MyTable'); var list = myTable.data('object').list; 

To unregister a List from a Model, just do this:


var myTable = skuid.$('#MyTable'); var list = myTable.data('object').list; var myModel = skuid.model.getModel('MyModel'); myModel.unregisterList(list); 

And so your complete strategy would be something like this:


var myTable = skuid.$('#MyTable'); var list = myTable.data('object').list; var myModel = skuid.model.getModel('MyModel'); myModel.unregisterList(list); myModel.save({callback:function(result){ myModel.registerList(list); }}); 

Nice, in this case, refactoring a dummy Model might just be easier, but this is really good stuff to know.