So I have the following line:
<%= f.input :birth_date, as: :date, label: "Date of Birth", html5: true, input_html: {min: Time.now.year - 100.year, max: Time.now} %>
Which is generating:
<input class="form-Field-control date required dr-FormField-control" aria-invalid="true" name="recommends_insurance_term_life_referral[birth_date]" id="recommends_insurance_term_life_referral_birth_date" type="date">
Any thoughts as to that for which I had not accounted?
As min and max you have to pass a Date object.
Date.today - 100.years
Related
my code looks like this
<div class="field form-group">
<%= f.label :date_of_birth %><br />
<%= date_select :date_of_birth, {order: [:month, :day, :year],
prompt: { day: 'Select day', month: 'Select month', year: 'Select year' },
start_year:1950, end_year: Date.today.year}, {required: true}, class: "form-control" %>
</div>
And result is in this photo
What i want that year selection be from 1950 to now.
Thanks for help!
The following code works perfectly for me:
<%= f.date_select( :date_of_birth, { :order => [:month, :day, :year], :start_year => 1950, :end_year => Date.today.year }, { :required => true, :class => "form-control" }) %>
Note that my date_select control is prepended with f, for the form it belongs to... I think that might be your problem.
<label class="control-label">count</label>
<%= f.number_field :count, {:placeholder => "Count", :class => "multiple_text_field form-control", :required => true, :max=>"8",:min=>"8" } %>
If you want to have exactly 8 digits, the min value would be 10000000 and the max value would be 99999999.
Yes, you have done it almost. A little change to this:
<%= f.number_field :count, {:placeholder => "Count", :class => "multiple_text_field form-control", :required => true, max: 8, min: 8 } %>
<%= f.number_field :count, max: 10, min:4 %>
try this :
<%= f.text_field :title, class: "form-control", title: "Enter title length 50 characters", placeholder: "Enter Title", :required => true,:maxlength => 50, pattern: ".{1,50}" %>
I'm using Simple Forms in Rails 4.2. I have the following date selector for birth dates on my form page. I want to display the months in the selector drop down list in the following format, 1-January,2-February,3-March... Instead of January,February,March. How can I do this?
<%= f.input :birth_date, as: :date, start_year: Time.now.year - 15, end_year: Time.now.year - 75,
order: [:month, :day, :year], default: nil, label: false, include_blank: true,
input_html: { style: 'margin: 15px 0px; display: inline-block; width: 110px;' } %>
You can get the result you are looking for by applying either of the 2 options:
add_month_numbers: true
month_format_string: "%<number>02d-%{name}"
So I currently have a simple_form set up and one of my inputs is:
<%= form.input :contract, input_html: { maxlength: 60 }, placeholder: "Contract Type", label: false %>
However I would instead like to change it into a dropdown with 3 options - full time, part time and internship.
What is the correct way to achieve this?
try this
<%= form.input :contract, collection: ['full time', 'part time', 'internship'], input_html: { class: "ui dropdown", maxlength: 60, }, prompt: "Contract Type", label: false %>
I use simple_form gem in my Rails app. When I use code like this
= f.input_field :name, label: false, placeholder: 'Name'
= f.input_field :price, label: false, placeholder: 'Price'
= f.input_field :description, label: false, placeholder: 'Description'
= f.input_field :image, label: false, placeholder: 'Image'
I get HTML for input:
<input class="string required textform" id="item_name" label="false" maxlength="255" name="item[name]" placeholder="Имя" size="255" type="text">
As you can see size of input is 255 now. Actually it's much more than enough. How can specify the size of inputs?
Following is from simple_form documentation here
It is also possible to pass any html attribute straight to the input,
by using the :input_html option, for instance:
<%= simple_form_for #user do |f| %>
<%= f.input :username, input_html: { class: 'special' } %>
<%= f.input :password, input_html: { maxlength: 20 } %>
<%= f.input :remember_me, input_html: { value: '1' } %>
<%= f.button :submit %>
<% end %>
To set size of 100 for name input:
= f.input :name, label: false, placeholder: 'Name', input_html: { size: 100 }