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

on "remove" event incompatibility with jquery #222

Closed
Valkhan opened this issue Apr 24, 2019 · 9 comments
Closed

on "remove" event incompatibility with jquery #222

Valkhan opened this issue Apr 24, 2019 · 9 comments

Comments

@Valkhan
Copy link

Valkhan commented Apr 24, 2019

When we have a tag input inside a container and we use: $('.container').empty(), it triggers the $('.tags').on('remove', ... ).

I believe that the name "remove" is conflicting with other similar events from jqueyr causing it to call tagify remove when it's not supposed to.

@yairEO
Copy link
Owner

yairEO commented Apr 24, 2019

If that is the case I would suggest not using Tagify's jQuery version but to use vanilla tagify.

Why does this matter you? what the actual bug?

@Valkhan
Copy link
Author

Valkhan commented Apr 24, 2019

This is my workflow:

  1. Open Modal
  2. Search for files
  3. Empty Files Container
  4. Append Files found with tags fields
  5. Select a file
  6. Close modal

My Tagify events: add, remove, edit, every time any of those are called, the tags for the given file is updated. It's worth mentioning that i'm using this library as is, no customization of any form.

The problem is: each time I "Empty Files Container" or "Close modal" that is a "destructive" operation, "removing" elements from DOM, it triggers the "remove" event bound to EVERY tag input, that means: if I have 1000 files listed, my server will receive 1000 tags update requests by closing a modal.

I Tried renaming the "remove" event from your sources with no success.

If you could point me to an example of having the same result I would gladly put to the test.

Some code to clarify what I have:

I've simplified the code as the logic is much more complex and won't be of use, so please give attention to the comments: PROBLEM ...

function appendSearchResult($ctx,fileList) {

    //-- Update file tags function
    let fTags = function () {
        //-- Gather tags on input and send to server by ajax
    };

    //-- Cleanup container
    //-- PROBLEM (Calling empty will call 'remove' event on existing tagify objects)
    $ctx.find('.fileResultContainer').empty();

    //-- $html = Build HTML from fileList and parse with jQuery adding some validation events

    //-- Create events on tag inputs
    $html.find('input.fileTags').tagify().on('add', fTags).on('remove', fTags).on('edit', fTags);

    $ctx.append($html);

}

function selectFile($file) {
    //-- Gather file info and trigger callback function
    //-- Close file search modal (bootstrap 4)
    //-- PROBLEM (Calling "hide" will call 'remove' event on existing tagify objects)
    $(this).parents('.modal').modal('hide');
}

@Valkhan
Copy link
Author

Valkhan commented Apr 24, 2019

If that is the case I would suggest not using Tagify's jQuery version but to use vanilla tagify.

Why does this matter you? what the actual bug?

Digging up a little more, i found out that on "remove" is used by jQuery UI and it's triggered when an object is removed, so the Actual Bug is probably naming conflict, instead of just adding the 'remove' event from your library, it's also defining that when input is removed from dom, it should also call my function.

My request is: is there a way to make it compatible without renaming your method (some kind of ".noConflict()" solution when extending jQuery with your library) or can you point me how to rename this event to: "tagRemoved" or something like that?

@yairEO
Copy link
Owner

yairEO commented Apr 24, 2019

But have you try not to use the jQuery version of Tagify? simply use tagify.min.js

Then the on method won't be jQuery's but Tagify's on, which is a whole different events system not shared with jQuery and will probably help in your situation

@Valkhan
Copy link
Author

Valkhan commented Apr 24, 2019

could you post an example for me, i'm very newbie on vanilla js events and selectors.

@yairEO
Copy link
Owner

yairEO commented Apr 25, 2019

Just don't use the jQuery version of Tagify but the normal version. switch the files.

There are many examples in the README

I will look just like your code now, only a slight different, just follow the guides, you'll understand it in no time

@yairEO yairEO closed this as completed Apr 25, 2019
@Valkhan
Copy link
Author

Valkhan commented Nov 28, 2019

Today i've taken some time to fix this on jQuery, for those who are bottered with the conflict with remove event from jQuery a simple solution is to rename the event on tagify as bellow:

From: customEventsList:["click","add","remove","invalid","input","edit"]
To: customEventsList:["click","add","removetag","invalid","input","edit"]

Find: .trigger("remove"
Replace: .trigger("removetag"

Usage:
From: $('input').on('remove', callback)
To: $('input').on('removetag', callback)

@yairEO
Copy link
Owner

yairEO commented Nov 28, 2019

you shouldn't modify the source code because I keep changing it and you will have to re-edit it every time I release a new version..

I will just make the fix in the code permanently and that's it. very soon I will releasing v3 and I will include it there (after inspection)

@yairEO yairEO mentioned this issue Dec 12, 2019
Merged
yairEO added a commit that referenced this issue Dec 12, 2019
- do not add multiple   after the last tag, in mixed-mode (happens if initial input value has multiline)
- re-wrote "replaceTextWithNode" method completely and renamed it "replaceTextWithNode"
- fix bug where unintended mixed-mode prefixes are removed instead of only the one needed
- fix bug with mixed-mode dropdown not removed when Tagify de-focus
- Changes to "autoComplete" setting. added "rightKey" sub-setting
- when dropdown is shown, pressing ESC key should not create a new tag, but only hide the dropdown
- improve the auto-comeplete setting with sub-settings for "enter" & "right" keys functionality (issue #103)
- on fuzzy-search, only auto-complete the input with terms starts with the typed text
- added loader animations to the CSS and "loading" method to Tagify
- single-value select mode refactoring
- demo page - suggestion list as tags that when clicked add the clicked tag
- renamed jQuery event "remove" to "removeTag" #222
- make demo page header fixed to top
- all triggered events return the instance's scope (tagify)
- add methods to the README (replaceTag)
- improved CSS dropdown animations (on show)
- Show dropdown suggestions list on arrow down #333
- fixed #267 - Pasted text separated with new line symbol doesn't process correctly
- fixed #356 - addTags not working on mix-mode
- add boolean property to "this.dropdown" that would tell if the dropdown is shown or not
- show suggestions dropdown when editing a tag
- add event: "edit:keydown"
- new event: "edit:input"
- new event: "edit:change"
- new event: "edit:start"
- added dropdown ability to use css effects when showing
- dropdown auto-adjusts its placement if there's no space for it at the bottom, it will flip to be above
@yairEO
Copy link
Owner

yairEO commented Dec 12, 2019

Just released version 3.0.0. This was fixed in the process.

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