Page 1 of 1

How to trigger change event on field

Posted: 31 Jul 2017
by chris.cook
Hi,

I have a form where many fields get filled in automatically from various AJAX requests. Upon returning and filling in their values, I need to trigger the change event on those fields, in order to complete more logic.

Currently setting the value of a FD field doesn't trigger the change event, nor does using the jquery style fd.field(fieldname).change(), or fd.field(fieldname).control()._el().change()
I thought that one of them would do it, but I can't seem to programmatically trigger the event. The only way I can think of doing it is attaching new functions as properties to the fd objects that require updates and manually calling that function when I update them, but if the functionality is already there I would rather not hack it like that.

What do I need to do in order to trigger the fd change event programmatically?

Re: How to trigger change event on field

Posted: 31 Jul 2017
by Nikita Kurguzov
Hello, Chris!
In order to trigger change you need to use this code:

Code: Select all

fd.field(fieldname).control()._el().find('input').trigger('change');
But in order to detect change use this code:

Code: Select all

fd.field(fieldname).control()._el().find('input').on("change", function(){
	//your code
});
Be careful with this code, as it should work for some fields, but not for all. If you have any difficulties with some types of fields, let us know.