Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form DSL support for formtastic's semantic_errors method #905

Merged
merged 4 commits into from
Sep 25, 2012

Conversation

robdiciuccio
Copy link
Contributor

Per formtastic docs [semantic_errors]:

Generates an unordered list of error messages on the base object and optionally for a given set of named attribute. This is idea for rendering a block of error messages at the top of the form for hidden/special/virtual attributes (the Paperclip Rails plugin does this), or errors on the base model.

A semantic_errors passthrough method was added to the ActiveAdmin::FormBuilder DSL, as well as basic CSS for display of the error messages.

Errors can be displayed at the top of the form by including the semantic_errors method. To display all model errors:

form do |f|
  f.semantic_errors *f.object.errors.keys
  f.inputs
  f.buttons
end

This is particularly useful when you have missing required nested attributes, for which no inline error messages are displayed:

form do |f|
  f.semantic_errors *f.object.errors.keys
  f.inputs
  f.inputs "Locations" do
    f.has_many :locations do |loc|
      loc.input :address
      loc.input :_destroy, :as => :boolean, :label => "Delete"
    end
  end
  f.buttons
end

@ghost ghost assigned gregbell Feb 7, 2012
jpmckinney pushed a commit that referenced this pull request Sep 25, 2012
Form DSL support for formtastic's semantic_errors method
@jpmckinney jpmckinney merged commit 2004b7c into activeadmin:master Sep 25, 2012
@jpmckinney
Copy link
Contributor

Thanks!

@pietschy
Copy link

pietschy commented Nov 6, 2012

I'm having issues with the last form buffer being clobbered when there are no errors. The following works fine when there are validation errors, but is missing the two boolean inputs if there are none (i.e. when you go to the edit screen).

form.inputs :name => "Has Cars", :class => "as_inline_form" do
     form.input :has_auto, :as => :boolean
     form.input :has_manual, :as => :boolean
     # this is clobbering the previous two elements when there are no errors
     form.semantic_errors :base 
end

UPDATE: This appears to be a formtastic issue as it's happening in regular partials as well.

@joseh-henrique
Copy link

Hello pietschy some time ago I opened an issue on inputs inline #1098 was - it was closed by pcreux, it seems that you got it

form.inputs :name => "Has Cars", :class => "as_inline_form"

to show how you could do? Responding to Set an easy way to put inline input fields open for me?

PS. Sorry, but I'm not good at css design and application refers to AA, ok?!

@gaganawhad
Copy link

I just wanted to make a note that when using the current version (f67be37) of master branch to displaysemantic_errors inside the has_many form fields, seems to display the errors correctly inside a wrapper with class 'errors' but doesn't set the color to red.

I use the code like:

form do |f|

  f.has_many :object do |object_form|
    object_form.semantic_errors :base
    object_form.input :color
  end

end

This seemed like the most appropriate place to make the comment rather than creating another issue.

bazlo added a commit to bazlo/active_admin that referenced this pull request Sep 10, 2013
Document the semantic_errors ability added in Pull request activeadmin#905

activeadmin#905
bazlo added a commit to bazlo/active_admin that referenced this pull request Sep 10, 2013
Document the semantic_errors ability added in Pull request activeadmin#905

activeadmin#905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants