I want to register a keypress event on the -postalcode input elements. Within the callback I need the current postalcode in order to send a request to an API fetching the corresponding city and state. As I want to do this on several modules (Leads, Accounts, Contacts) and reuse the script on several instances, I put the code into a dedicated controller which is then inserted into the record and create layout.
The problem is, that I cannot register the keypress events in the initialize function as the input fields are not there at this point. They only appear after edit was clicked. I tried doing this:
this.events['keypress input[name=' + zipField + ']'] = _.bind(this.getCityAndStateByZip, this);
I circumvented the problem with some ugly keyup event on document:
$(document).on('keyup', _.bind(this.getCityAndStateByZip, this));
Where I had to get the actual zip value in the callback via jQuery and still did not know which field actually has changed. The postalcode of the primary address oder the alt address?
Is it possible to only register some event to a single field? Preferably a key event where I can get the current input value in the callback?!