Conditiona Rendering and save issue in Skuid

I am facing one issue in Skuid conditional rendering and want to know if there is simple workaround for this in Skuid. When the component (e.g. field, tab) hides based on some defined render condition and if user has already entered the data in them before hiding…then what happens is data gets saved to SF record when the save button is clicked. Actually those hidden fields should be blank on the detail record when it is saved. Can you please let me know how I can accomplish this in Skuid? Do I need to customize the save button? Is there a point-and-click way? Thanks in advance!

There is probably a way in javascript.

Would be nice to get the option to reset field values to their original state if hidden due to conditional rendering.

I think only way forward is to create custom javascript save button. Pls let me know if my understanding is not correct. Anyone has examples for such Skuid button ?

Unless there is a method to detect which fields are hidden, then you’d have to recreate the conditional rendering results in javascript in order to know which are hidden. I as well would like to know the answer to this.

Best way forward would certainly be to have conditional rendering also automatically reset the values upon the hiding fields.

I completely agree!! Thanks..!

I think this is very common scenario and feel Skuid should address this issue on priority. The reason I started building Skuid pages for my client is because of conditional rendering feature it provides but did not know that it has this issue.


The reason why this is problematic to implement in Skuid is that you could technically have multiple input / output fields associated to a Model data field, so Skuid can’t automatically “know” that it should clear data in fields when they are hidden, as this may not be desired behavior. 

We understand that this is an issue though, and are considering adding a “Clear data in field when hidden” option at the field level, which would accomodate this. 

In the meantime, this is achievable via JavaScript fairly easily.

You could implement this from a custom Save button, or you could have it happen immediately whenever an affected field’s value is changed.

Here is sample JavaScript that you can use to clear values in hidden fields immediately when the values in certain fields are set to certain values. 

(a) This should be added as a JavaScript Resource with Resource Location “Inline”
(b) Here is the resource body:

(function(skuid){<br>&nbsp; &nbsp;var $ = skuid.$;<br>&nbsp; &nbsp;$(function(){<br>&nbsp; &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; var myModel = skuid.model.getModel('Case');<br>&nbsp; &nbsp; &nbsp; var myRow = myModel.getFirstRow();<br>&nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; var fieldsToClearByValueByField = {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Status': {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'New': ['New_Sub_Status__c','AccountId','ContactId'],<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Working': ['Working_Sub_Status__c','Description','AccountId','ContactId','Priority']<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Boolean_Field_1__c':{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; false: ['Boolean_Field_2__c','Secondary_Field__c']<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Boolean_Field_2__c':{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; false: ['Secondary_Field__c']<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; };<br>&nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp;'row.updated',function(changeInfo){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (myRow.Id===changeInfo.rowId){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.each(changeInfo.updates,function(fieldId,newValue){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var clearings = fieldsToClearByValueByField[fieldId];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (clearings){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var fieldsToClear = clearings[newValue];<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (fieldsToClear){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var updates = {};<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $.each(fieldsToClear,function(i,fieldToClear){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; updates[fieldToClear]=null;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (skuid.utils.size(updates)){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myModel.updateRow(myRow,updates);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; });<br>&nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp;});<br>})(skuid);

Some explanation here:

Where you will be making changes is to fieldsToClearByValueByField. Basically at the top level of this object we are saying, “When these fields are changed…” (e.g. when “Status” is changed, or when “Boolean_Field_1__c” is changed), then at the 2nd level we are saying, “If the field has been changed to this value” (e.g. when “Status has been changed to ‘Working’, then”, or when “Boolean_Field_1__c” has been changed to false), and at the 3rd level we are saying “Go clear the values of all of these fields” (e.g. when Boolean_Field_1__c has been changed to false, go clear the values of Boolean_FIeld_2__c and Secondary_Field__c). 

Thanks Zach for detailed reply! I think better way is to implement custom save button rather than immediate field value clearing. This way, user can still toggle between field hides and retain already eneterd values before clicking on save. However, all the values should be cleared for hidden fields when the save button is clicked. It would be really helpful for me if you can give me examples of such custom save button. Thanks again!


Here is an example of a custom Save Snippet that would do this:

var params = arguments[0];<br>var model = params.model;<br>var row = params.row;<br>var $ = skuid.$;<br>var fieldsToClearByValueByField = {<br> 'Status': {<br> 'New': ['New_Sub_Status__c','AccountId','ContactId'],<br> 'Working': ['Working_Sub_Status__c','Description','AccountId','ContactId','Priority']<br> },<br> 'Boolean_Field_1__c':{<br> false: ['Boolean_Field_2__c','Secondary_Field__c']<br> },<br> 'Boolean_Field_2__c':{<br> false: ['Secondary_Field__c']<br> }<br>};<br>var updates = {};<br>$.each(model.changes[row.Id],function(fieldId,newValue){<br>&nbsp; &nbsp;var clearings = fieldsToClearByValueByField[fieldId];<br>&nbsp; &nbsp;if (clearings){<br> &nbsp; var fieldsToClear = clearings[newValue];<br> &nbsp; if (fieldsToClear){<br> &nbsp; $.each(fieldsToClear,function(i,fieldToClear){<br> &nbsp; updates[fieldToClear]=null;<br> &nbsp; });&nbsp;<br> &nbsp; }<br>&nbsp; &nbsp;}<br>});<br>if (skuid.utils.size(rowUpdates)){<br> model.updateRow(row,rowUpdates);<br>}<br>;