0

I'm working on an input helper class in JS with jQuery. The class should be able to autocorrect inputs like "2,99" to "2.99" or "1200" to "12:00" based on what class the input field has. No hard task but since I really don't want to bind the class to all input fields manually I tried using the .on('blur','.__gui_helper, GUIH.blur) method.

So far so good and works as expected. BUT! If I add another blur handler to a single input field it will always fire first! Which makes sense in the way the .on() method is working. But is there any way to get around this?

I guess I could use the .keyup() method but actually, I don't need to check the correct format on every keystroke.

P.S. it is NOT a duplicate on how to change the order of execution of events. read the question again. or get to know how .on() works to fully understand the question -_- There is no way to sort the execution with the data attribute or smth.

mercsen
  • 692
  • 1
  • 5
  • 21
  • Possible duplicate of [How to order events bound with jQuery](https://stackoverflow.com/questions/290254/how-to-order-events-bound-with-jquery) – freedomn-m May 25 '17 at 07:44
  • There's a number of other SO answers with similar issues – freedomn-m May 25 '17 at 07:44
  • Possible duplicate of [jQuery event handlers always execute in order they were bound - any way around this?](https://stackoverflow.com/questions/2360655/jquery-event-handlers-always-execute-in-order-they-were-bound-any-way-around-t) – JNF May 25 '17 at 07:45
  • I guess your code runs like `$(document).on('blur', '.__gui_helper', GUIH.blur)`, which means that jQuery will see the event only when it reached the `document` level. Which is quite after that a handler bound to the element fires. If you don't add fields on the fly, you could bind the handler to the element. – Misu May 25 '17 at 07:47
  • @JNF i actually know about the "duplicates" but this is a complete other case. Since i dont bound events in a specific order, this has to to with the way the .on() methods works. It seems only Misu is getting the point. @ Misu i know i could do that but not all fields are created on the fly since i use a template system :( – mercsen May 25 '17 at 07:56
  • @mercsen, how about putting it as a callback in the first? – JNF May 25 '17 at 08:03
  • in what first? i dont understand ^^ – mercsen May 25 '17 at 08:04

0 Answers0