ruby-on-railsactiveadminformtastic

ActiveAdmin invalid form still submit


In ActiveAdmin I have a form with typed inputs and required fields, and even If I let required fields blank or put numbers in email typed input, I am still able to perform submit even if the form is not valid.

my code :

ActiveAdmin.register User do
  actions :all, except: [:destroy, :edit]

  permit_params :email

  form do |f|
    f.semantic_errors
    f.inputs 'Invite a new user' do
      f.input :email, required: true, input_html: {required: true, type: "email" }, as: :email
      f.input :first_name
      f.input :last_name
    end
    f.actions
  end

Solution

  • This issue is due to the fact that formtastic puts "novalidate" by default on all forms :

    https://github.com/formtastic/formtastic/issues/1001

    The fix is to create an initializer and update default formtastic config where it make sense for you such as :

    # config/initializers/formtastic.rb
    # Formtastic is the form builder used by ActiveAdmin
    
    # You can find the original config file here:
    # https://github.com/formtastic/formtastic/blob/master/lib/generators/templates/formtastic.rb
    
    # You can opt-in to Formtastic's use of the HTML5 `required` attribute on `<input>`, `<select>`
    # and `<textarea>` tags by setting this to true (defaults to false).
    Formtastic::FormBuilder.use_required_attribute = false
    
    # You can opt-in to new HTML5 browser validations (for things like email and url inputs) by setting
    # this to true. Doing so will omit the `novalidate` attribute from the `<form>` tag.
    # See http://diveintohtml5.org/forms.html#validation for more info.
    Formtastic::FormBuilder.perform_browser_validations = true