Changes in the form are not saved to database

后端 未结 4 1334
轻奢々
轻奢々 2020-12-08 03:16

I\'m trying to add a date field to my form.

I added bootstrap-datepicker-rails gem, all required css and javascript.

When I choose the date in the calendar a

4条回答
  •  感情败类
    2020-12-08 04:11

    I´ve used the anwser from Andrew. It worked well for me, except that it not displayed the localized month names correct (For example July instead of Juli).

    Here is my approach, if you want to use a localized version for your date_picker.

    By default the bootsrap-datepicker gem loads all language versions.

    If you want for example to load only the english and german version you have to change application.js

    from

    //= require bootstrap-datepicker
    

    to

    //= require bootstrap-datepicker/core
    //= require bootstrap-datepicker/locales/bootstrap-datepicker.en-GB.js
    //= require bootstrap-datepicker/locales/bootstrap-datepicker.de.js
    

    Nest step is to change BootstrapDatepickerInput

    What we want now is that the language is dynamically choosen from a given parameter.

    so add the following line to you Input class inside of the input method

    set_data_option text_field_options, 'date-language', input_html_options[:locale]
    

    In our view we can call now the form with

    = f.input :your_attribute_name, as: :bootstrap_datepicker, input_html: { locale: locale }
    

提交回复
热议问题