KaneCohen/tokenfield

Tokenfield does not respect existing field value

Opened this issue · 1 comments

When a form is returned by the server for render, the input element where I need my data has existing values already in place.

Imagine you are in the edit page of an article and there is a field for the article name, and a field where you add tags. You write a draft of your article, add some tags, and save it for later. When you come back, you load your article edit page again and the data entered previously, including the tags, should be displayed just as before. Now I can add more tags, or subtract some from last time.

However, with Tokenfield, this data (which would generally be a string of ID values or delimited plain text values, depending on your tagging strategy) is not used when generating the tag selection widget. It is ignored.

If I submit my form again, in fact, the new ids do not get appended to my original tag list.

I realize Tokenfield has a definable property when you create the instance that is where I could enter my existing data. But that's duplication of code and forces me to generate the Tokenfield javascript in line with my page render code in order to be able to write the string into the js declaration.

I also realize Tokenfield has the itemName property that will relay the final list of fields back to the server for saving. If there are any situations where I want to use Tokenfield for different fields, this also messes up my ability to create one independent block of javascript that manages any and all instances of tags in my application.

Hello.

I realize Tokenfield has a definable property when you create the instance that is where I could enter my existing data. But that's duplication of code and forces me to generate the Tokenfield javascript in line with my page render code in order to be able to write the string into the js declaration.

This is an expected behavior - I imagine in most cases input field with IDs doesn't have additional data required for the Tokenfield to operate (such as name property). Maybe only in case of some dynamically generated <select> input that would work. And doing a XHR request to fetch additional data doesn't seem quite right.

I'll consider adding code which will look for related data- attributes in provided element as a possible source of items.