Search code examples
ruby-on-railsformsuser-inputactiveadminrequired

ActiveAdmin set a form input as required for creation


I seem to be having an issue where using ActiveAdmin 2.9 and I am requiring a title for creation utilizing input_html: {required: true} And it is still allowing me to submit forms without a title. Is there something else I have to do for Active Admin to validate this title requirement? Below is my form for clarity.

form title: 'Notes' do |f|
 f.inputs 'Note' do  
  f.semantic_errors
  f.input :topic
  f.input :title, input_html: {required: true}
  f.input :body, as: :quill_editor
 end
  f.actions
end


Solution

  • It's not clear whether you mean the browser (html5) validation or the Rails validation. I think you mean the html5 validation since it will actually prevent the submission. The browser html5 validation in formtastic is opt in, it won't work unless you turn it on.

    You need to create a formtastic initializer (config/initializers/formtastic.rb) and put this in: Formtastic::FormBuilder.perform_browser_validations = true