Rails 3 Formatastika. How can I make formtastic display only the fields of the month and year WITHOUT a day?

I need formtastic to display only the fields of the month and year, WITHOUT the fields of the day.

Datpicker is good, but shows the entire calendar. I do not want a dumper.

f.input :accounting_month, :label => "Accounting month", :as => :datepicker

I only need a month and a year.

+4
source share
3 answers

This does not work, because without a day it means 28-31 (depending on the month) days, and it can be any of them. If you want to keep the monthly selection without a day, you will see that this is a date range, not the date “a”.

The date tip always saves the entire date as a date field. If you only know the month and year, you need to have two (non-dates) fields, one for each. But, as you can see, this will lose you a lot, and you will need to configure each field, check it, etc. Big pains, so good reasons are enough for this.

The only thing I can offer is: create a hidden div or apply css if you cannot "enter" the standard date field in the form for the "day". Then set the value always to 01. Then you can have a "date" field, which will store the 01-month year in the database. This is definitely a “hack”!

+2
source

There is a way to do this:

 <%= f.input :accounting_month, :label => "Accounting month", :order => [:month, :year] 

This will automatically hide the day entry and give it a default value of 1.

+5
source

try it

 f.input :accounting_month, :as => :date_select, :discard_day => true 
+3
source

Source: https://habr.com/ru/post/1393441/


All Articles