javascript - How to enter value of datepicker into text field -
i have list of tasks , each task has edit date option use jquery datepicker for.
this application.js:
$(function() { $('.date').datepicker({dateformat: 'yy-mm-dd'}); });
this _edit_form.html.erb:
<%= form_for task |f| %> <div class='form-group'> <%= f.text_field :description, placeholder: 'create task' %> </div> <div class='form-group'> <%= f.label :due_date %> <%= f.text_field :due_date, placeholder: 'select date', class:"date", readonly: 'readonly' %> </div> <%= button_tag(type:'patch', class:"btn btn-default btn-xs") %> <span class='glyphicon glyphicon-plus'></span> <% end %> <% end %>
so problem datepicker works first task on list. can pick date, it'll show in text field , it'll pass task#update
controller fine.
however, every task after isn't able receive input datepicker. text field blank when select date, , doesn't pass controller. when debug in web console, 'value' = "".
this jquery problem using datepicker on multiple fields. it's not rails's fault...
i think answer need "apply jquery datepicker multiple instances": attach unique id
each field, script function below:
html:
<input type="text" class="datepick" id="date_1" /> <input type="text" class="datepick" id="date_2" /> <input type="text" class="datepick" id="date_3" />
script:
$('.datepick').each(function(){ $(this).datepicker(); });
Comments
Post a Comment