snippet to execute each time UI field's value is changed (without saving)

  • 1
  • Question
  • Updated 3 years ago
Hi,

Is it possible for an In-Line Js Snippet to execute each time a UI-Only field's value is changed (without saving ofc, as Ui -only field won't keep value..)

So each time Ui-Only field named : paid_percentage is changed for this inline-snippet to run

var params = arguments[0],   $ = skuid.$;var model = skuid.$M('FundingPerformance');
var row = model.getFirstRow();
var dateVar = row.Effective_Balance_Date__c;
var daystoadd = row.days_to_add;
var newdate = row.Date_percentage_reached;
//convert from Salesforce date to Javascript date
var jsDate = skuid.time.parseSFDate(dateVar);
//add days
jsDate.setDate(jsDate.getDate() + daystoadd);
//convert from Javascript date back to Salesforce date
var daysAdded = skuid.time.getSFDate(jsDate);
model.updateRow(row,{Date_percentage_reached : daysAdded});


Thx
Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Mordechai

Mordechai

  • 968 Points 500 badge 2x thumb
you'd create a custom renderer and add an onchange handler to the field.
Photo of Chris Herr

Chris Herr

  • 436 Points 250 badge 2x thumb
Hi Dave

As Mordechai already wrote, a Custom Field Renderer is the way to go.

It should look something like this:

var field = arguments[0],    value = arguments[1],
    $ = skuid.$;
    
    field.element.append(
    skuid.ui.renderers.TEXT.edit({
        inputType: 'text',
        value : field.row[field.id],
        onChange : function( value ) {
        //Your Action here
       // To run your Snippet use 
       // skuid.snippet.getSnippet('SnipetName')();
            console.log("On Change Event");
        }
}));

Make sure to change "TEXT" to whatever Type your UI Only Field is.
Photo of Chris Herr

Chris Herr

  • 436 Points 250 badge 2x thumb
This would be an easier version of this code: 

var field = arguments[0], 

    value = arguments[1], 

    model = field.model, 

    row = field.row, 

$ = skuid.$; 


field.element.change(function(){ 

    //some actions after the value of the element has changed 

}); 

skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field, value);

Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb
Thank you Chris, I just tried the easier version with added Action: skuid.snippet.getSnippet('SnipetName')();

And it works like a Charm :)

Thx!