$on('change') of Single Line of Text Fields

Good Morning,

I am having a major issue with the On Change event trigger for a single line of text field.

The on Change Triggers the second a user begins to type in the field, so for example using the code you suggest: -

fd.field('Quotation_x0020_Title').$on('change', function(value) {
	alert('New value: ' + value);
});

If I want to type “Test” into the field I get an alert on pressing “T”, and then another alert on pressing “e”, and then again on pressing “s” and yet again on pressing “t”.

I need to only trigger the event once the user has finished typing into the field or deselected the field. I trying to run a function that updates an item in another list with the changes made to the field and the above is causing this function to fail and also really slowing down the form…

This was not an issue in Forms Designer as the on change triggered once the field was deselected.

1 Like

Dear Tony,
I see! Yes, in fact the behavior of the event has changed since Forms Designer to allow for more flexibility, but it does seem lacking in cases such as this. We’re going to look into it.

Meanwhile, you can try the following JS:

var test;
$(fd.field('Title').$el).find('input')[0].onfocus = function() {
  test = fd.field('Title').value;
  console.log(test);
};

$(fd.field('Title').$el).find('input')[0].onblur = function() {
  if (fd.field('Title').value != test) {
    alert("Changed from: " + test + "\nto: " + fd.field('Title').value);
  }
};
1 Like

Hi Nikita,

Any way to apply the same thing to a people picker field. I have a function firing on change and it seems to be behaving in the same way, do I use the same code as shown above?

Thanks,
Andy

Dear @abolam,
People Picker should work the same way, so the code above will help. Accessing value is different for People Picker though, so you might need to change from that:
fd.field('Title').value
to:
fd.field('Person').value.DisplayText