The number of errors in a form includes several errors for the same field. For example, if a title is mandatory and has to have at least 5 characters, leaving the title blank will result in two errors. So users will be invited to look for two errors, but they'll only find one field with errors. So it's a bit more intuitive to show as many errors as fields having errors. Note we're excluding errors on `:base`, which is a bit of a hack for errors in association fields. For example, if the title of one translation is not present, `resource.errors.messages` will contain two elements: one for the translation's title, and one for the `base` field. This resulted in the count of errors being 2 when there was only one. Also note I haven't found a way to count errors on all `has_many` relations. That is, if two translations have a missing title field, only one error will be mentioned in the message (as it did before this commit).
20 lines
694 B
Plaintext
20 lines
694 B
Plaintext
<% if resource.errors.any? %>
|
|
<div id="error_explanation" data-alert class="callout alert" data-closable>
|
|
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
|
|
<strong>
|
|
<% errors_count = resource.errors.messages.reject { |attribute| attribute == :base }.count %>
|
|
|
|
<%= pluralize errors_count, t("form.error"), t("form.errors") %>
|
|
|
|
<% if local_assigns[:message].present? %>
|
|
<%= message %>
|
|
<% else %>
|
|
<%= sanitize(t("form.not_saved", resource: t("form.#{resource.class.to_s.underscore}"))) %>
|
|
<% end %>
|
|
</strong>
|
|
</div>
|
|
<% end %>
|