代码之家  ›  专栏  ›  技术社区  ›  Schwern

如何在ActiveAdmin中使用日期选择器而不重写create表单?

  •  0
  • Schwern  · 技术社区  · 6 年前

    /admin/<model>/new

    我想用选择器代替。但我发现的所有关于使用日期时间选择器的文档似乎都需要重写整个表单。似乎没有办法只更改一个输入,也没有等效的 preserve_default_filters!

    我想更改所有日期和日期时间列的默认值,例如。。。

    config.datepicker = ...
    

    或者每列,比如。。。

    column :signed_up, as: :datetime_picker
    

    默认情况下,我得到与此等价的新表单和编辑表单。

    form do |f|
      f.semantic_errors
      f.inputs
      f.actions
    end
    

    signed_up 要使用日期选择器,我必须重复默认情况下提供的所有列,只需更改一列的输入类型。

    ActiveAdmin.register Thing do
      form do |f|
        t.semantic_errors
        t.input :name
        t.input :this
        t.input :that
        t.input :signed_up, as: :datepicker
        t.input :other
        t.input :thing
        t.input :left
        t.input :right
        t.actions
      end
    end
    

    0 回复  |  直到 6 年前