How to run a snippet when checkbox selected or unselected?

  • 1
  • Question
  • Updated 1 year ago
  • Answered
I searched with all search engines and nowhere I could find an answer to this simple questions. Just when I thought I've learnt enough SKUID for a day, I ran into this. I would like to run a snippet when a checkbox is clicked. Let's say my script is as follows:
var params = arguments[0],
    $ = skuid.$;
var CHECKBOX_FIELD = "Some__c";
var idsOfRowsThatAreChecked = [];
var item = arguments[0].model;
var row = arguments[0].row;

var mymodel= arguments[0].model
$.each(mymodel.data,function(i,row){
   if (mymodel.getFieldValue(row,CHECKBOX_FIELD)===true){
        idsOfRowsThatAreChecked.push(row.Id);
   }
});

if(idsOfRowsThatAreChecked.length>=2){
    alert("More than one item selected");
}

How can I run this snippet when a checkbox is checked/unchecked? My understanding of the snippets is that they would run on load or when a button is clicked. How about a checkbox?
I am thinking the events have to be bound to the snippet. Am I wrong?
Thanks
murthy
Photo of Murthy Gandikota

Murthy Gandikota

  • 200 Points 100 badge 2x thumb

Posted 1 year ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Model Actions is your answer. You can set to run actions on "When Row is Updated" and select the field in question. Then you can select the snippet you created.
Photo of Murthy Gandikota

Murthy Gandikota

  • 200 Points 100 badge 2x thumb
Thank you, sir. You made my day!