How do I set the value of a model UI only field via Javascript so that it can be evaluated within a condition?

  • 1
  • Question
  • Updated 3 years ago
  • Answered
  • (Edited)
I want to verify certain properties of a model are filled out right before allowing a user to click a Submit button.

My plan is to disable the button and enable it based on the result of a JavaScript snippet that is being run.

There may be an easier way to do this but what i am trying is to create a UI.Only checkbox field in the model. Then set that field via the JavaScript snippet if the entries validate via my custom code.

If so then there would be an enable condition on the button which would then allow the user to click the submit button.

Here is what I have tried.

var model = skuid.model.getModel(theModel),
row = model.getFirstRow();
console.log(row.applicationComplete);
row.applicationComplete=true;
console.log(row.applicationComplete);

The first log comes through as undefined. The second shows as true. So the row seems to be updating in memory but the field is not showing the check in the checkbox on the page and my button which has a condition looking for applicationComplete to be true does not seem to see that the value has been set.

I am missing some sort of a step just not sure which one(s).
Photo of Joseph Ucuzoglu

Joseph Ucuzoglu

  • 1,074 Points 1k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Mordechai

Mordechai

  • 968 Points 500 badge 2x thumb
Why don't you just use the "Enable Conditions" in the "Rendering" section for that button?
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Nice.  Be easy when you can..... 
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Hey guys - As mentioned in his OP, Joseph is planning on using the "enable conditions" feature.  His challenge is that the button isn't enabling.

Joseph - The reason your button isn't enabling is because you are not updating the row via the Skuid API and instead directly modifying the "row" object.  The skuid API is required to update data so that all the skuid magic can happen (e.g. notify anyone and everything that cares that there was a data change).

In order to get your button to enable, try the following:

var model = skuid.model.getModel(theModel),
row = model.getFirstRow();
model.updateRow(row, 'applicationComplete', true);

Couple of notes:
1) Make sure you use the correct Field name - field names are case-sensitive.  If you're field is "ApplicationComplete" and not "applicationComplete" make sure you use the correct name.
2) You can check out the updateRow API along with all other Model API's at http://help.skuidify.com/m/11720/l/205447-skuid-model-model