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

Replaced global selectors in $ function in rails_admin.dom_ready event h... #1671

Merged
merged 1 commit into from
Jun 14, 2013
Merged

Replaced global selectors in $ function in rails_admin.dom_ready event h... #1671

merged 1 commit into from
Jun 14, 2013

Conversation

scarfacedeb
Copy link
Contributor

I noticed that event handlers on rails_admin.dom_ready contain code that init jQuery plugins with css selectors like this: $('form [data-...]').
These handlers are being called when you add new tab in has_many forms. (inside handler for nested:fieldAdded).
And you don't need to init all plugins in the form. Only the ones that was added.
That's why when I'm passing additional scoping variables to event handlers that help to narrow scope of css selectors.
It affects nested-form and remote-form handlers.


You can use scoping in your custom event handlers for rails_admin.dom_ready too.
Like this:

$(document).on( 'rails_admin.dom_ready', function( e, content ){
    var content = content ? content : $('form');

    // initialize tagit plugin as an example.
    content.find('.comma-separated').tagit();
});

I've found another rails_admin.dom_ready event handler in ui.js:61, but I'm not sure if it needs to be scoped like this.

…t handlers to narrower optional find() calls
@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 18a7407 on scarfaceDeb:scoped-dom_ready into ca15a8f on sferik:master.

sferik added a commit that referenced this pull request Jun 14, 2013
Replaced global selectors in $ function in rails_admin.dom_ready event h...
@sferik sferik merged commit ab1db7d into railsadminteam:master Jun 14, 2013
@sferik
Copy link
Collaborator

sferik commented Jun 14, 2013

Thanks!

@scarfacedeb scarfacedeb deleted the scoped-dom_ready branch June 14, 2013 19:59
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.

3 participants