id as 'datepicker' being replaced by model field 'due_date' while using datepicker in rails form

StackOverflow https://stackoverflow.com/questions/23385448

سؤال

I have the following in a form,

 <div class="row">
      <%= t.label :name, 'Due Date' %><br>
      <%= t.text_field :due_date, id: 'datepicker' %>
 </div> 

The id attribute is required to show jquery datepicker. But rails replaces the id attribute value with the field name of the form i.e due_date. This causes validation error for first time date selection but works fine in second time selection.It should not show validation error when date is selected for first time.

I would appreciate your help.

هل كانت مفيدة؟

المحلول

Hope t is a form object, then Try with:

<div class="row">
      <%= t.label :name, 'Due Date' %><br>
      <%= t.text_field :due_date, :value => "", :id=>"datepicker" %>
 </div>

Hope it helps :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top