jQuery datepicker not initialized after partial inserted -
i have rails 4 application uses turbo links , jquery.turbolinks. uses jquery date picker plugin.
i using ryan bates' technique adding/editing multiple models in 1 form, railscast episode #196 nested model form.
in case, adding/editing people associated household. person_fields partial includes birthdate field 'attempts' utilize date picker (a string input class="datepicker"), doesn't work, datepicker doesn't appear when click on field class of '.datepicker'.
with other forms loaded page, datepicker works fine. form added dynamically code, datepicker doesn't appear.
here's code link inserts partial:
def link_to_add_fields(name, f, association) new_object = f.object.send(association).klass.new id = new_object.object_id fields = f.fields_for(association, new_object, child_index: id) |builder| render(association.to_s.singularize + "_fields", f: builder) end link_to(name, '#', class: "add_fields little round button success", data: {id: id, fields: fields.gsub("\n", "")}) end
and coffee script inserting partial:
$('form').on 'click', '.add_fields', (event) -> time = new date().gettime() regexp = new regexp($(this).data('id'), 'g') $(this).before($(this).data('fields').replace(regexp, time)) event.preventdefault()
and coffee script date picker:
$('.datepicker').datepicker()
any help much appreciated.
--- update ---
thanks billy monk's suggestion, code add together fields looks this:
$('form').on 'click', '.add_fields', (event) -> time = new date().gettime() regexp = new regexp($(this).data('id'), 'g') $(this).before($(this).data('fields').replace(regexp, time)) event.preventdefault() $('.datepicker').datepicker()
and works! much appreciated! take reply i'm allowed.
in javascript function adds new fields add together $('.datepicker').datepicker() after have been added. datepicker won't automatically bind newly added elements.
jquery jquery-plugins ruby-on-rails-4
No comments:
Post a Comment