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

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

Projects
None yet
6 participants
Contributor

robdiciuccio commented Jan 13, 2012

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 added a commit that referenced this pull request Sep 25, 2012

Merge pull request #905 from robdiciuccio/master
Form DSL support for formtastic's semantic_errors method

@jpmckinney jpmckinney merged commit 2004b7c into activeadmin:master Sep 25, 2012

Contributor

jpmckinney commented Sep 25, 2012

Thanks!

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.

Hello pietschy some time ago I opened an issue on inputs inline gregbell#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?!

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.

madeindata added a commit to madeindata/active_admin that referenced this pull request Sep 10, 2013

Add form semantic_errors usage to documentation
Document the semantic_errors ability added in Pull request #905

activeadmin#905

madeindata added a commit to madeindata/active_admin that referenced this pull request Sep 10, 2013

Add form semantic_errors usage to documentation
Document the semantic_errors ability added in Pull request #905

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