How do I run a function and re-render a field each time an input field value is changed?

edited April 2019 in Questions
I am assigning this custom snippet to a currency field. My objective is to place commas in the appropriate places as the user is typing. But for now the code is trying to replace the value of 2000 into the field whenever a character is entered into the input.

There are two issues I am having with the code below:

  1. The change event seems to only activate after I click out of the field. I would actually like this action to re-evaluate the fields value each time a character is entered or deleted.
  2. The field is added over and over and over again each time the function is run rather than updating the value and refreshing the existing field.
Here is my broken code:

var $ = skuid.$;
var field = arguments[0];
var value = arguments[1];
model = field.model, row=field.row, $=skuid.$;

field.element.change(function(value){
   value = 2000;
   skuid.ui.fieldRenderers[field.metadata.displaytype]['edit'](field,value);
});

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

Comments

Sign In or Register to comment.