How do I store additional field value data?

How do I store additional field value data?

bigbenchrobbigbenchrob Posts: 26Questions: 9Answers: 2

I'm writing a typeahead plugin, in which the user's input into the input field is used to present a set of matching items from a key->value list (e.g. {'id' : '1',' text' : "dog"}, {'id' : '2', 'tex' t: "cat},...). The plugin will autocomplete the users selection, filling the editor form field with the text portion. However, I also need to store the id value (hidden from the user of course).

I thought about storing it as an extra value in the editor's data property, a la ajax.data, but this doesn't seem to be created until the form is being prepared to be submitted (Am I wrong about this?!!!). In any case, where could I store a bit of extra data as the field is being edited? (I know I could set a cookie but maybe there's a cleaner way). Thanks very much in advance!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    A couple of options:

    1. If it is only required by the plug-in you could attach it to the conf parameter (passed in as the first parameter to all field plug-in methods) and give it a name that doesn't conflict with any of the built in names (use double underscore to start the parameter name for example).
    2. The plug-in could add an <input type="hidden"> field into the DOM when it creates its DOM elements which could be used to store the data
    3. The value could be attached as a custom property to the DOM input element (myInputEl.__myId = 1; for example).

    Allan

This discussion has been closed.