Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Tagging: handling invalid and/or multiple entries by the tagging function #485

Closed
darrudi opened this issue Dec 8, 2014 · 6 comments
Closed
Labels

Comments

@darrudi
Copy link

darrudi commented Dec 8, 2014

Feature Request regarding free tagging:
The user may enter a string which is considered invalid by the tagging function. So the tagging function should be able to return null upon receiving the input. I did this but a bunch of errors surfaced. My tagging function (an email client):

    $scope.uiSelectNewTag = function(email){
        email = email.trim();

        if (email.match(/^[a-z][a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i)) {
            var newItem = {
                type: 2,
                email: email,
                key: email
            };
            return newItem;

        } else {
            return null;
        }
    };

Also the user may copy-paste a string (e.g. a list of emails separated by semicolons) into the ui-select and the tagging function may decide there are more than one item in the input. So I guess its a good idea to have the tagging function return an array (zero or more items) instead of a string.

@NJAldwin
Copy link

Regarding the second point: couldn't you solve that by using tagging-tokens?

I'm all for the main issue here, namely adding some sort of tag validation.

@darrudi
Copy link
Author

darrudi commented Jan 11, 2015

Regarding tagging-tokens:
I doubt if copy-pasting data containing several tagging-tokens (; for example) into the ui-select input would trigger the tagging function several times. I did not give it a try. The current tagging function does not support other desirable functionality, i.e. it does not create a tag onBlur, so I could not actually use it. I ended up to customizing ui-select to implement the missing features.

@vdsabev
Copy link

vdsabev commented Jan 16, 2015

@darrudi we have the exact same use case with emails:

  1. Adding entries via the tagging feature
  2. Copy-pasting what could be multiple entries
  3. Adding the entry on input blur
  4. Not adding invalid entries at all

Would you mind sharing how you customized the plugin to achieve this?

EDIT: Never mind, I ended up using the https://github.com/mbenford/ngTagsInput plugin, which was specifically built for tagging.

@darrudi
Copy link
Author

darrudi commented Jan 17, 2015

@vdsabev: sorry for my delay. Anyway, I guess you'd be better off with ngTagsInput as my customizations were somehow hackish.

@LeleDev
Copy link

LeleDev commented Jan 19, 2015

+1 for this feature.

It would be really really useful to be able return a null with the tagging function when you don't want to add a not-valid field, it's quite a common case

@dimirc
Copy link
Contributor

dimirc commented Feb 18, 2015

Seems to be resolved with #678 and #664

@dimirc dimirc closed this as completed Feb 18, 2015
@dimirc dimirc added the tagging label Feb 18, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants