Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokenfield does not respect existing field value #50

Open
cal-zone opened this issue Feb 14, 2021 · 1 comment
Open

Tokenfield does not respect existing field value #50

cal-zone opened this issue Feb 14, 2021 · 1 comment

Comments

@cal-zone
Copy link

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.

@KaneCohen
Copy link
Owner

KaneCohen commented Feb 14, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants