I have a UI Only checkbox field called ‘Hide’ on the work experiences model.(I have this field updated to = ‘true’ on a particular row via a row action) I am trying to create a snippet which will return true when any row has had this field updated to ‘true’. Then I am hoping to use this snippet for an enable condition to enable another field on the same model. This snippet below doesnt seem to work(I can verify x=true once I update only the top row to hide=true. Any ideas as to what I’m doing wrong?
$ = skuid.$;
var weModel = skuid.$M(‘WorkExperiences’);
var weList = weModel.getRows();
var x;
for (var i = 0; i < weList.length; i ++) {
if (weListbi].Hide === true) {
x= true;
break;
}
else{
console.log(‘No’);
x=false;
}
}
You should be able to do this declaratively. Fileds can be enabled based on the results of UI fields (unless I am missing something). So in Skuid, in the field settings, in the “rendering” tab, you should be able to create an enable condition based on the value in your UI only field.
Hello Danny - From a snippet perspective, you are missing a return statement. Without a return statement, skuid will evaluate your snippet to ‘undefined’ which is not equal to true. In order to return true (or false) from the snippet, add the following as the last line of your snippet:
return x;
I actually tried this first. However, again, it only works when I update the first row of ‘WorkExperiences’ to Hide=true. I’m not sure why this is happening.
I tried this as before as well. However, I get - Uncaught SyntaxError: Illegal return statement
If you are getting an exception, then there is likely something wrong with the javascript code. Can you paste provide the full JS you tried to use that included the return statement?
$ = skuid.$;var weModel = skuid.$M(‘WorkExperiences’);
var weList = weModel.getRows();
var x;
for (var i = 0; i < weList.length; i ++) {
if (weListei].Hide === true) {
x= true;
break;
}
else{
console.log(‘No’);
x=false;
}
}
return x;
also tried
(function() {$ = skuid.$;
var weModel = skuid.$M(‘WorkExperiences’);
var weList = weModel.getRows();
var x = false;
for (var i = 0; i < weList.length; i ++) {
if (weListwi].Hide === true) {
x= true;
}
else{
x=false;
}
return x; }
}())
and
$ = skuid.$;
var weModel = skuid.$M(‘WorkExperiences’);
var weList = weModel.getRows();
var x;
$.each(weList,function(i,row) {
if (row.Hide === true) {
x=true;
return false;
}
else{
x=false;
}
return x;
});
thanks so much for the help! I am brand new to JS and I appreciate the feedback!
Barry can attack it from the JS angle. He is smarter than me . Declaratively, you can create a one row model on any object. Create a UI only field on that model that is a checkbox. Then the row actions in your primary model will update that UI field on the one row object to true (checked). Then base your enable condition on that one row model’s UI only checkbox.
Raymond - Appreciate the compliment but not smarter, just different skillsets
Btw, There is a way to accomplish what you are after using JS as well but it involves a “Tracker” model as well or an approach that uses undocumented APIs which aren’t recommended.
That worked!! Thank you both Also, I had a feeling the way I was using my snippet was wrong because it would only be evaluated on page load (not subsequent during updates). Would another way to achieve this be via firing off a snippet during row action (the same one that updates hide=true) that would update field mode from ‘read only’ to ‘edit’ ??
Glad it worked Danny!
Just to clarify, the problem with the evaluation wasn’t because you were using inline (instead of inline snippet) directly. Using inline would definitely cause the code to evaluate only 1 time (on page init) but even with inline (snippet), the snippet would only be evaluated once because of the limitation with skuid currently. The hope is that skuid adds a way to “inform” Skuid when configuration (snippet returns true) when the snippet itself needs to be re-evaluated/called.
Regarding row action and then field mode, you could approach it this way but it would not be recommended. For starters, it’s undocumented and not officially supported. Ideally, skuid will add a “changeMode” API to facilitate this. That said, I have code written (as do others) that directly manipulate the mode of components, fields, etc. and there are situations where its the only option but they are few and far between. In your case, you can accomplish what you 100% declaritively so I’d highly recommended sticking with that route.
Excellent! Thank you both again. These tips are invaluable;)
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.