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

Check for duplicates before submitting data in backend #17

Open
bezin opened this issue Apr 3, 2019 · 3 comments
Open

Check for duplicates before submitting data in backend #17

bezin opened this issue Apr 3, 2019 · 3 comments
Assignees
Labels

Comments

@bezin
Copy link
Contributor

bezin commented Apr 3, 2019

Hello there,

thanks for this awesome bundle. I implemented in a recent project and I am most pleased :-)

I experienced one UX issue while editing some content: I entered a couple of tags to a dataset from a list my client gave me. I did not realize the list contained some duplicates.

What happened

  • Enter Chai => Tag does not exist yet => Add Chai =>Chai is added to the tags list

  • Continue enter plenty more tags.

  • Save in between.

  • Enter Chai again => Tag is already in list and does exist in Database, but selectize.js does not check that -> Add Chai -> Chai is added to the tags list.

  • Chai is added two times now

  • On submit, an SQL error will be thrown: When the bundle tries to add the second Chai, the first one is already stored in the database:

An exception occurred while executing 'INSERT INTO tl_cfg_tag (`tstamp`, `name`, `source`) VALUES (1554295030, 'Chai', 'app.trader_tags')':

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'Chai-app.trader_tags' for key 'name_source'

This is quite annoying from an UX perspective.

What should happen

  • I would expect a duplicate check whether the given term was already entered before
  • I would than expect a message like "Tag already in list"

What do you think? I could provide a PR.

Cheerio

EDIT: I edited this issue to be more precisely: If a term is not saved yet, you cannot add it twice to the tags list. Selectize.js takes care of that. However, if you saved once, you can easily add an already added and saved tag multiple times, causing the SQL Expection.

@bezin
Copy link
Contributor Author

bezin commented Apr 3, 2019

I tracked this further down:

The issue lies here:

if (self.items.indexOf(value) !== -1) {
if (inputMode === 'single') self.close();
return;
}

and here:

options.create = function (input) {
return {
value: input,
text: input
}
};

The selectize.js duplicate check looks for values; if we add Chai for the second time, it will be added with an value of Chai. The first Chai item is in the list with value of the corresponding id e.g. 123. Hence it will be added twice.

I therefore suggest, to check here, whether there already is a tag with the same name and source before finally returning null and creating a new tag.

if (null === ($model = $adapter->findByPk($value))) {
return null;
}

@qzminski
Copy link
Member

Hey, sorry for the super late reply… I'd be very glad if you can provide a PR!

@frontendschlampe
Copy link

@bezin do you will provide any PR? ;-)

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

No branches or pull requests

3 participants