Skip to content
This repository

Cannot assign a "default_value" to a Date field within RailsAdmin config #1353

Closed
bvaughn opened this Issue · 3 comments

3 participants

Brian Vaughn Mitsuhiro Shibuya Benoit Bénézech
Brian Vaughn

Here's a snippet from my RailsAdmin config:

RailsAdmin.config do |config|
  config.model Element do
    edit do
      field :date_start do
        default_value do
          Date.current
        end
      end
    end
  end
end

When I load the :create action for Element, I see an empty input box for "date_start". If I look at the HTML however, I see that the current Date default was at least partially passed on by RailsAdmin:

<input data-datetimepicker="true" data-options="{&quot;datepicker&quot;:{&quot;dateFormat&quot;:&quot;MM dd, yy&quot;,&quot;dayNames&quot;:[&quot;Sunday&quot;,&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;],&quot;dayNamesShort&quot;:[&quot;Sun&quot;,&quot;Mon&quot;,&quot;Tue&quot;,&quot;Wed&quot;,&quot;Thu&quot;,&quot;Fri&quot;,&quot;Sat&quot;],&quot;dayNamesMin&quot;:[&quot;Sun&quot;,&quot;Mon&quot;,&quot;Tue&quot;,&quot;Wed&quot;,&quot;Thu&quot;,&quot;Fri&quot;,&quot;Sat&quot;],&quot;firstDay&quot;:1,&quot;monthNames&quot;:[&quot;January&quot;,&quot;February&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;,&quot;August&quot;,&quot;September&quot;,&quot;October&quot;,&quot;November&quot;,&quot;December&quot;],&quot;monthNamesShort&quot;:[&quot;Jan&quot;,&quot;Feb&quot;,&quot;Mar&quot;,&quot;Apr&quot;,&quot;May&quot;,&quot;Jun&quot;,&quot;Jul&quot;,&quot;Aug&quot;,&quot;Sep&quot;,&quot;Oct&quot;,&quot;Nov&quot;,&quot;Dec&quot;],&quot;value&quot;:&quot;&quot;},&quot;timepicker&quot;:{&quot;amPmText&quot;:[&quot;&quot;,&quot;&quot;],&quot;hourText&quot;:&quot;Hour&quot;,&quot;minuteText&quot;:&quot;Minute&quot;,&quot;showPeriod&quot;:false,&quot;value&quot;:&quot;&quot;},&quot;showTime&quot;:false}" id="element_date_start" name="element[date_start]" size="30" type="text" value="2012-10-05" />

However, if I edit one of Elements, I see that RailsAdmin set the date value in an additional place (down inside fo the data-options attribute):

<input data-datetimepicker="true" data-options="{&quot;datepicker&quot;:{&quot;dateFormat&quot;:&quot;MM dd, yy&quot;,&quot;dayNames&quot;:[&quot;Sunday&quot;,&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;],&quot;dayNamesShort&quot;:[&quot;Sun&quot;,&quot;Mon&quot;,&quot;Tue&quot;,&quot;Wed&quot;,&quot;Thu&quot;,&quot;Fri&quot;,&quot;Sat&quot;],&quot;dayNamesMin&quot;:[&quot;Sun&quot;,&quot;Mon&quot;,&quot;Tue&quot;,&quot;Wed&quot;,&quot;Thu&quot;,&quot;Fri&quot;,&quot;Sat&quot;],&quot;firstDay&quot;:1,&quot;monthNames&quot;:[&quot;January&quot;,&quot;February&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;,&quot;August&quot;,&quot;September&quot;,&quot;October&quot;,&quot;November&quot;,&quot;December&quot;],&quot;monthNamesShort&quot;:[&quot;Jan&quot;,&quot;Feb&quot;,&quot;Mar&quot;,&quot;Apr&quot;,&quot;May&quot;,&quot;Jun&quot;,&quot;Jul&quot;,&quot;Aug&quot;,&quot;Sep&quot;,&quot;Oct&quot;,&quot;Nov&quot;,&quot;Dec&quot;],&quot;value&quot;:&quot;October 04, 2012&quot;},&quot;timepicker&quot;:{&quot;amPmText&quot;:[&quot;&quot;,&quot;&quot;],&quot;hourText&quot;:&quot;Hour&quot;,&quot;minuteText&quot;:&quot;Minute&quot;,&quot;showPeriod&quot;:false,&quot;value&quot;:&quot;00:00&quot;},&quot;showTime&quot;:false}" id="element_date_start" name="element[date_start]" size="30" type="text" value="2012-10-04" />

Am I missing something? Or is this a defect?

Brian Vaughn

Bump.
Been over a week and no response. Anyone home? :)

Benoit Bénézech
Collaborator

bump on #1366

Mitsuhiro Shibuya mshibuya closed this
Mitsuhiro Shibuya
Collaborator

Fixed by #1383.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.