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

Data Manipulator / Corrector before adding value #190

Merged

Conversation

tsai146
Copy link
Contributor

@tsai146 tsai146 commented Aug 4, 2014

I was wondering is there a way to manipulate the value before added.
My case is to change the value to lower case.
I saw there is beforeItemAdd event, but I cannot update the value. (kind of like #135)

@rlidwka
Copy link
Contributor

rlidwka commented Aug 2, 2014

I think you can cancel event, and then create a new one with modified object (or just add tag yourself).

It's overly complicated though.

@timschlechter
Copy link
Contributor

I think we can do this by making just a small change in the source. We just need to continue with event.item just after beforeItemAdd, instead of item.

@tsai146
Copy link
Contributor Author

tsai146 commented Aug 4, 2014

I like @timschlechter 's native approach.
I will try to create the patch

@tsai146
Copy link
Contributor Author

tsai146 commented Aug 4, 2014

I am having issue to install grunt on my box so I cannot run build.
However, I did test it manually and it seems working.
I am just doing the way you suggested.

rlidwka added a commit that referenced this pull request Aug 6, 2014
Data Manipulator / Corrector before adding value
@rlidwka rlidwka merged commit 728a609 into mdbootstrap:master Aug 6, 2014
@rlidwka
Copy link
Contributor

rlidwka commented Aug 6, 2014

Yeah, it works. Thanks.

I wonder if it makes sense to do the same for beforeItemRemove.

@tsai146
Copy link
Contributor Author

tsai146 commented Aug 6, 2014

I think we need to leave beforeItemRemove alone.
If we manipulate the removed item value, we might not be able to find the match.

$('.tag', self.$container).filter(function() { return $(this).data('item') === item; }).remove();
$('option', self.$element).filter(function() { return $(this).data('item') === item; }).remove();
if($.inArray(item, self.itemsArray) !== -1)
  self.itemsArray.splice($.inArray(item, self.itemsArray), 1);

@tsai146 tsai146 deleted the before-item-add-data-manipulation branch August 6, 2014 17:36
@barisusakli
Copy link

Even though this is merged it doesn't seem to work on 0.8.0.

Canceling the event and adding it manually works though.

tagEl.on('beforeItemAdd', function(event) {
    var modifedTag = event.item.toLowerCase();
    event.cancel = modifiedTag !== event.item;
    if (event.cancel) {
        tagEl.tagsinput('add', cleanTag);
    }
});

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

Successfully merging this pull request may close these issues.

4 participants