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

Add explanation on how to display errors on fields inside fields_for #133

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions _includes/forms.html
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,23 @@ <h3 id="form-errors">Errors</h3>
</form>
{% endhighlight %}

<p>Note that fields inside <code>fields_for</code> submitted with invalid values are <strong>not</strong> automatically highlighted. The <code>:errors</code> options should be specified explicity so that BH recognizes the <code>:errors</code> options.</p>
{% highlight rhtml %}
<%= f.fields_for :company, fields_set: false, errors: {icons: true, messages: true} do |company_form| %>
<%= company_form.text_field :name %>
<% end %>
{% endhighlight %}
<p>However, error messages in the association attribute should still be displayed manually.</p>
{% highlight rhtml %}
<% if @user.company.errors.any? %>
<ul class="errors">
<% @user.company.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
<% end %>
{% endhighlight %}

<h3 id="form-help">Help text</h3>
<p>Use the <code>:help</code> option to display a help message after fields inside <em>bootstrapped</em> forms.</p>
<p>Note that error messages will have precedence over help messages.</p>
Expand Down