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

Items should split if not in quotes #10

Closed
joshkersey opened this issue Jul 1, 2016 · 3 comments
Closed

Items should split if not in quotes #10

joshkersey opened this issue Jul 1, 2016 · 3 comments
Assignees

Comments

@joshkersey
Copy link

joshkersey commented Jul 1, 2016

I've been hacking at this for a few hours now and can't come up with a solution so I'm hoping that I can present the issue I'm seeing to get someone else's eyes on this.

Here are the steps to recreate the issue:

  1. User with an empty input enters the string foo bar in the input.
  2. The term foo bar is not an existing Tag object so the user chooses "Add foo bar..." in the results pane.
  3. Selectize creates a single item that reads foo bar.

The problem here is that there are no double quotes around foo bar within the underlying hidden form input and so when the object is saved in the Django admin django-taggit will split the string into two separate tags foo and bar.

This is a confusing user experience as one would expect selectize to have created two separate items rather than initially rendering it as one item. I played around with the taggit-selectize widget but could not come up with a solution that would split the items before rendering. Any ideas on how to get selectize to split the input into two items rather than rendering as a single item?

@chhantyal
Copy link
Owner

Thanks for detailed issue report. That is definitely bug, @nshafer do you have any pointers for OP?

@nshafer nshafer self-assigned this Aug 2, 2016
@nshafer
Copy link
Collaborator

nshafer commented Aug 2, 2016

First, I apologize for not getting back to you.. I've just moved cities and things were really hectic.

So, I just looked into this, and was able to replicate it. With further digging, I've come across the basic problem that Selectize and default Taggit have differing philosophies when it comes to supporting tags separated by either commas or spaces.

Selectize has a default delimiter setting of of a comma, in the delimiter setting. With taggit-selectize, we do not change this setting nor do we expose it to the user through our own settings. I think I'll change this.

Taggit, on the other hand, has a default string-to-tag parser that tries to be intelligent and parse tags separated by spaces if there are no quotes or commas in the string. So the problem here is that according to Selectize, the string "foo bar" is a single tag, so no commas or quotes are necessary. This then gets posted to Taggit, which says, "hey there, no commas, no quotes, this must be a space-separated tag list" and then pulls each word out separately as a distinct tag.

So the good news is that this is fixable, but really only by the user changing Taggit's default configuration.

Taggit has a setting that allows you to override the default tag parser, documented here. Their example creates a super naive parser that causes other problems with how Selectize works, so instead I have adapted a version of their tag parser that will still properly work with quotes and commas, but doesn't ever treat spaces as a separator.

I have included this function in taggit_selectize.utils.parse_tags and updated the README to reflect the extra step of configuring Taggit to use it during installation.

TAGGIT_TAGS_FROM_STRING = 'taggit_selectize.utils.parse_tags'

I am going to make another change or two and have Nar push a new version to PyPi.

@nshafer nshafer closed this as completed Aug 2, 2016
@nshafer
Copy link
Collaborator

nshafer commented Aug 3, 2016

I have released these fixes in a new version. Thanks for the report and the help!

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

3 participants