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

Making jQuery event work with nod #97

Closed
lucmazon opened this issue Feb 11, 2015 · 8 comments
Closed

Making jQuery event work with nod #97

lucmazon opened this issue Feb 11, 2015 · 8 comments

Comments

@lucmazon
Copy link

Hello,

I couldn't make the jQuery trigger('change') work when modifying an input field with jquery val('value').
This seems to be related to the problem described in this ticket: http://bugs.jquery.com/ticket/11047

Here's a simple example showing the problem : http://jsfiddle.net/404xxouw/2/

I get that it's more a jQuery issue than a nod one, but seeing how jQuery is widely used, would there be a way to make nod work seemlessly with jQuery ? (I'm not good enough in javascript to now if it's possible or not ^^).

Thanks a lot!

@casperin
Copy link
Owner

Hi. :) You are exactly right, except it isn't really a bug in jQuery, but rather a conscious choice on their part. That sucks, but I can definitely understand them. Thanks for bringing it to my attention.

The only real option I see, is to detect whether jQuery is present, and if so, use its event system to listen for jQuery changes. It's not pretty, but it should work.

However, even this solution has its limitations (even though I already use it in .getElements()), which is that of relying on a global variable being present. The user may have renamed it (to avoid conflicts maybe), or it may be part of a bigger app where everything is being required in the individual files. So maybe the right option would be to add something like

var myNod = nod({jQuery: $});

to explicitly let nod.js know that it's okay to use jQuery, and where to find it.

I'll give this one some thought and get back to you. Thanks for using nod.js. It warms my heart to hear when my little project here solves actual problems for people. :)

Btw. I updated your example, to be a little easier to work with: http://jsfiddle.net/404xxouw/3/

@lucmazon
Copy link
Author

Sorry I didn't issue a pull request myself, I'm definitely not good enough in javascript to modify properly your code :) But I think the solution of adding a configuration telling the library to use jquery is a good one !

@casperin
Copy link
Owner

Don't worry about that. It'll come. Your issue here was a good help for me. I'll do the rest ;)

@casperin
Copy link
Owner

I think I might like the idea of adding it as an argument. I could extend that to adding underscore if you want me to use underscore's _.each instead of .forEach if you want support for ie lower than 9.

@lucmazon
Copy link
Author

You're right, that would be cool too ^^

@casperin
Copy link
Owner

Hep! Solved :) Check here:
https://github.com/casperin/nod#triggerevents

I decided to just go with the configure object, and then I added the possibility to just pass that in upon creation:

var myNod = nod({
    delay: 400,
    jQuery: $
});

I also added https://github.com/casperin/nod#force-nod-to-perform-a-check (see issue #96) that you might find interesting (sort of does the same thing, but differently).

@lucmazon
Copy link
Author

Awesome! I'm actually using both functionalities now! Keep up the good work ;)

@casperin
Copy link
Owner

👍 Good to hear.

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