javascript - datepicker js with rails strange thing -


i'm developing app , want show datepicker js in field inside form have little problem, hope can me.

my app uses modal bootstrap load forms, f.e. when click button "new task" modal appears form add new task, so, in form have text field :date want complete datepicker js. problem datepicker never appears if run code in .js in console datepicker appears normally.

i added jquery-ui-rails , in application.js , application.css requires. here code.

application.js

//= require jquery //= require jquery_ujs //= require jquery-ui/datepicker //= require turbolinks //= require bootstrap.min //= require_tree . 

application.css

 *= require jquery-ui/datepicker  *= require bootstrap.min  *= require font-awesome  *= require sb-admin  *= require_self  *= require_tree 

i have file custom_script.js in app/assets/javascripts these code

$(document).ready(function($) { $('.datepicker').datepicker(); }); 

and _form.html.haml:

=form_for([@list, @list.tasks.build]) |t| =t.label :name, class: 'control-label'   =t.text_field :name    =t.label :date,  "expiration date", {class: 'control-label'}   =t.text_field :date, {:class => "datepicker", "readonly" => "readonly"}    =t.label :active, class: "checkbox inline"     =t.check_box :active     %span active?    =t.submit class: 'btn btn-primary' 

so, problem when click text_field datepicker not appear if run code inside custom_script.js in console datepicker appears normally.

i've tried page:load because use turbolinks didn't work, so, don't know i'm doing wrong.

the form loaded ajax call because button "new task" has remote: true, so, think problem, dont know how solve it.

i hope can me people!

here's what's happening. after load page, code $('.datepicker').datepicker(); called. when introduce modal, code not run again. try adding

javascript:  $(document).ready(function($) {    $('.datepicker').datepicker();  }); 

to bottom of my _form.html.haml. way, after file loaded js run.

or keep consistent have, use on method in js file...

$(document).ready(function($) {   $(document).on('load','.datepicker',function(){     $('.datepicker').datepicker();    });  }); 

what , forever attach datepicker .datepicker.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -