You are viewing limited content. For full access, please sign in.

Question

Question

Triggering Error Messages

asked on June 17, 2019

I have error message defined in a form to display when currency value exceeds maximum. I am using javascript to set maximum value of currency field. Error message displays for existing rows. But, if I add new rows, the message does not appear. Any thoughts please?

 

Thanks

Priya

0 0

Replies

replied on June 17, 2019 Show version history

JQuery .on method is a bit odd. If you just give the field within your table a class name and you state

$('.myFieldClass input').on('change', function)


It will look for only existing fields with that class and only monitor for changes to those, any new ones added later will be ignored.

However if you ALSO give the table a class name you can say

$('.myTableClass').on('change','.myFieldCLass input', function)



And it will always run your function regardless of when the field is added to the form

I am guessing this is because the .on is now running on something that already existed and never changes, and the field definition has been moved inside of the method itself.

0 0
replied on June 17, 2019 Show version history

To provide some background on this, you're right about it having to do with whether or not something exists when .on() is called.

JQuery .on() is attaching an event and it won't run again unless you call the function again.

Example 1 attaches handlers to the inputs that exist at that time.

Example 2 attaches handlers to the table, with added event delegation to target specific changes to it's child elements.

The second one works because the handler is already monitoring the parent; the "target" is part of the event so it can be identified on execution instead of just on binding.

1 0
replied on June 18, 2019

Thanks

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.