assign class id to an input field
so there I have this code in rails
<%= f.label :year, "Year:" %><br />
<%= f.text_field :year %></p>
that returns in html a cod开发者_如何学Ce like this one
< input id="car_year" name="car[year]" size="30" type="text" class="hasDatepicker"><br />
see the class="hasDatepicker"? I use the jquery to get the calendar to select dates this one is working good
but here is another one (using meta_search https://github.com/ernie/meta_search)
<td>
<%= f.label :year_gte, "Years from" %><br />
<%= f.text_field :year_gte, :size => 8 %></td>
that outputs an html code like this one
< input id="search_year_gte" name="search[year_gte]" size="8" type="text"><br />
obvius this one is missing the class="hasDatepicker" that needs the jquery to display the calendar
The question is: How do I get the class thing to display in that field Thanks all for your time.
Update 2 I just found the problem I need an javascript code in my view for search_year_gte as I have one for car_year looks like
<script>
$(function() {
$( "#search_year_gte" ).datepicker({
dateFormat: 'yy-mm-dd',
yearRange: '1980:2012',
changeMonth: true,
changeYear: true
});
});
</script>
<script>
$(function() {
$( "#search_year_lte" ).datepicker({
dateFormat: 'yy-mm-dd',<br />
yearRange: '1980:2012',<br />
changeMonth: true,
changeYear: true
});
});
</script>
but can I just use one script for both values? for search_year_lte and search_year_gte
Did you try adding the class as an attribute?
<%= f.text_field :year_gte, :size => 8, :class => "hasDatepicker" %>
Have a look at the documentation if you want to know what attributes you can pass to the text_field helper.
精彩评论