-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
If you add datetime picker as nested attribute, it won't work #1651
Comments
Duplicate #1646? |
Nope, it is not a duplicate, it is separate issue. #1646 is about the fact, that active admin css prevents using date/time addon to standard jquery ui date picker (but standard date picker works fine). This issue is about the fact, that even if you use standard and working date picker (without time addon) and put it in nested set, dynamically added fields with date are not reacting to click. |
live() syntax is obsolete now in jQuery, proper code is $(document).on('click', 'body.active_admin a.button', function() {
$('input.datepicker:not(.hasDatepicker)').datepicker();
}); |
@saepia, isn't this a better option? (replacing the version in the AA initializer) $(".datepicker").on 'focus', ->
$(this).datepicker dateFormat: 'yy-mm-dd' |
@daxter your code will not handle date pickers added in nested forms, after the AA initializer is called and will unnecessarily call datepicker() on fields that are already datepickered. Something between my and your proposal could be $(document).on 'focus', 'body.active_admin input.datepicker:not(.hasDatepicker)', ->
$(this).datepicker dateFormat: 'yy-mm-dd' It should work on all fields, regardless if they were rendered by rails or added later in JS and has as narrow selector as it is reasonable. |
Shouldn't you write it the opposite way? Is there some benefit to referencing $('.active_admin .datepicker:not(.hasDatepicker)').on 'focus', ->
$(this).datepicker dateFormat: 'yy-mm-dd' I don't think it's necessary to define |
The code you wrote is not going to work for nested forms as it binds event Please refer to live() docs in jQuery manual, it is clearly stated that BTW AA's jquery gem dependency should match version that introduced this I don't think performance and readability is key issue here as AA UI is |
I disagree that the distinction is clearly stated in the docs, but a quick jsfiddle confirmed your point. |
From: http://api.jquery.com/live Rewriting the .live() method in terms of its successors is straightforward; these are templates for equivalent calls for all three event attachment methods: $(selector).live(events, data, handler); // jQuery 1.3+
$(document).delegate(selector, events, data, handler); // jQuery 1.4.3+
$(document).on(events, selector, data, handler); // jQuery 1.7+ |
#1879 has been merged, should resolve this issue. |
I found bug in activeadmin 0.5.0.
If I define nested set in form, using .has_many declaration, newly added fields that should be datepickers, are not active. Propably JS hooks for datepickers are called only on page load, not after adding each child record.
I've added following code to active_admin.js and it solves the issue:
Maybe it should be added to default activeadmin JS?
The text was updated successfully, but these errors were encountered: