I just want to disable or hide minutes in time_select in the rails form.
My motive is to prevent user to modify minutes, only he is allowed to modify hours not minutes.
<%= f.input :start_time, as: :time_select, hint: "Time is storing in UTC", include_blank: false %>
Done with jquery by inspecting minute field ID. :)
$(document).ready(function(){
$('#property_promotion_start_time_5i').attr('disabled', 'disabled');
})
:) :)
Related
So, I have a rails application which there is a datepicker. When I put the date for the first time in the calendar it appears in this format: dd-mm-yyyy.
But rails save in the database in this format: yyyy-mm-dd.
When I go to edit this in the form, the datepicker get crazy, it appears a 1900 year, not the actual year.
I know this happens because the format date is different(the date which bootstrap expects and the date which is saved).
I tried change the datepicker format in the edit view(.html.erb) but it doesn't work. How can I solve this?
<%= f.text_field :my_date, "data-provide" => 'datepicker',
'data-date-format' => 'dd-mm-yyyy', class: 'datepicker form-control', :required => true %>
Is there a proper way to show 12-hour time in Rail's simple_for_for? I am currently using
<%= f.input :time, :ampm => true, :minute_step => 5 %>
however it only displays two drop downs, with the times displayed as 01AM in the first dropdown and 00 in the second.
I would like it to have three drop downs, for hours, minutes, and am/pm.
As per the documentation
HTML 5 date / time inputs are not generated by Simple Form by default, so using date, time or datetime will all generate select boxes using normal Rails helpers. We believe browsers are not totally ready for these yet, but you can easily opt-in on a per-input basis by passing the html5 option:
<%= f.input :time, as: :time, html5: true %>
This should fix your problem.
In my app, users should only be able to select times between 10am and 12pm, and then 4pm and 6pm. Basically I want my 'hours' drop-down menu to only list "10am, 11am, 12pm" and "4pm, 5pm, 6pm". Is this possible?
<%= f.time_select :time,
{ampm: true,
ignore_date: true,
start_hour: 10,
end_hour: 18,
discard_minute: true,
prompt: true,
prompt: { hour: "Choose hr" }
} %>
can be a start? may be you can write a script to disable the other hours or you use JavaScript to genereate the html options for you?
Has anyone come across this? I can't set the defaults for my time with the form while it is associated with my model
e.g.
<%= f.datetime_select :date_start, { default: #event.date_start.in_time_zone(current_user.time_zone), ampm: true, use_short_month: true, start_year: Time.now.year, end_year: Time.now.year+1, minute_step: 5}, class: 'form-control form-control-date' %>
The reason I need defaults because it defaults to utc. I need the edit form to factor in the time zone otherwise the user will see the wrong time they entered.
As it is, it ignores the default completely and leave it in UTC. This is an issue in the edit form.
If I change it to a tag, the default works. However I would need to change all my forms to tag so the form submits properly.
Anyone have a fix besides possibly doing that?
I need formtastic to display only month and year fields, WITHOUT the day fields.
The datepicker is nice but it shows the whole calendar. I don't want the datepicker.
f.input :accounting_month, :label => "Accounting month", :as => :datepicker
All I need is the month and year.
There is a way to do this:
<%= f.input :accounting_month, :label => "Accounting month", :order => [:month, :year]
This will automatically hide the "day" input and give it a default value of 1.
try this
f.input :accounting_month, :as => :date_select, :discard_day => true
It doesn't work that way because without day this implies 28-31 (depending on month) days and it could be any one of them. If you use want to store a month-year selection without day you'll see it is a range of dates, not "a" date.
Advice with dates is to always store the whole date as a date field. If you only know month and year you'll need to have two (non-date) fields, one for each. But as you can see it's going to lose you a lot and you'll need to custom craft each field, validate it, etc. major pain so needs pretty good reason to do it..
The only other thing I can suggest is:
create a hidden div, or apply css if you can't 'get inside' the standard date field on the form, for the 'day'. Then set the value to always be 01. Then you might have a 'date' set of fields that will save 01-month-year to the database. This is definitely a 'hack'!
With the new syntax in Ruby 1.9
f.input :date, as: :date_select, discard_day: true