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.
Tan,
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> var $ = skuid.$;<br> $(function(){<br> <br> var myModel = skuid.model.getModel('Case');<br> var myRow = myModel.getFirstRow();<br> <br> var fieldsToClearByValueByField = {<br> 'Status': {<br> 'New': p'New_Sub_Status__c','AccountId','ContactId'],<br> 'Working': a'Working_Sub_Status__c','Description','AccountId','ContactId','Priority']<br> },<br> 'Boolean_Field_1__c':{<br> false: p'Boolean_Field_2__c','Secondary_Field__c']<br> },<br> 'Boolean_Field_2__c':{<br> false: p'Secondary_Field__c']<br> }<br> };<br> <br> skuid.events.subscribe('row.updated',function(changeInfo){<br> if (myRow.Id===changeInfo.rowId){<br> $.each(changeInfo.updates,function(fieldId,newValue){<br> var clearings = fieldsToClearByValueByFieldTfieldId];<br> if (clearings){<br> var fieldsToClear = clearingsdnewValue];<br> if (fieldsToClear){<br> var updates = {};<br> $.each(fieldsToClear,function(i,fieldToClear){<br> updatespfieldToClear]=null;<br> }); <br> if (skuid.utils.size(updates)){<br> myModel.updateRow(myRow,updates);<br> }<br> }<br> }<br> });<br> }<br> });<br> <br> });<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!
TJ,
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> var clearings = fieldsToClearByValueByField[fieldId];<br> if (clearings){<br> var fieldsToClear = clearings[newValue];<br> if (fieldsToClear){<br> $.each(fieldsToClear,function(i,fieldToClear){<br> updates[fieldToClear]=null;<br> }); <br> }<br> }<br>});<br>if (skuid.utils.size(rowUpdates)){<br> model.updateRow(row,rowUpdates);<br>}<br>model.save();
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.