I just implemented a form for contact data that is related to a contract with our firms customers where I used awesomeplete for autocompletion on multiple input fields.
Because it occurs very often that the contact data for the new contract is already known to the database I wanted the autocompletion to fill out all fields if the user selects a suggestion from the list.
I had all the contract data instances from the database converted into JSON and used that as the list for each awesomeplete instance.
Configuring each awesomeplete instance to set it's input's value to the field value from the contract data object selected by the user was easy, but i also needed to set the values of the other inputs.
To do this I would need to know at the time when the user selects a suggestion which contract data object was the one whose representation was selected by the user.
This proved itself relatively uneasy since the 'awesomeplete-select'-event only has a reference to the selected html-representation of the contract data instance that was selected by the user and not to the contract data itself.
My solution was to give each contract data instance a unique id (the primary key from the database) and write that id as a data-attribute into the representation and read that in the handler function for the 'awesomeplete-select'-event.
This feels kind of hacky.
Is there a "cleaner" way to do this, which i missed?
I just implemented a form for contact data that is related to a contract with our firms customers where I used awesomeplete for autocompletion on multiple input fields.
Because it occurs very often that the contact data for the new contract is already known to the database I wanted the autocompletion to fill out all fields if the user selects a suggestion from the list.
I had all the contract data instances from the database converted into JSON and used that as the list for each awesomeplete instance.
Configuring each awesomeplete instance to set it's input's value to the field value from the contract data object selected by the user was easy, but i also needed to set the values of the other inputs.
To do this I would need to know at the time when the user selects a suggestion which contract data object was the one whose representation was selected by the user. This proved itself relatively uneasy since the 'awesomeplete-select'-event only has a reference to the selected html-representation of the contract data instance that was selected by the user and not to the contract data itself.
My solution was to give each contract data instance a unique id (the primary key from the database) and write that id as a data-attribute into the representation and read that in the handler function for the 'awesomeplete-select'-event.
This feels kind of hacky.
Is there a "cleaner" way to do this, which i missed?