confirmation validation error attribute #5942

Merged
merged 4 commits into from Apr 29, 2012

Projects

None yet
@bcardarella
Contributor

This will render the error message on :#{attribute}_confirmation instead
of on attribute itself. When rendering confirmation errors inline on the
form with form builders such as SimpleForm and Formtastic it is
confusing to the end user to see the confirmation error message on the
attribute element. Instead it makes more sense to have this validation
error render on the confirmation field instead.

The i18n message has been updated for the confirmation validator error
message to include the original attribute name.

@bcardarella bcardarella confirmation validation error attribute
This will render the error message on :#{attribute}_confirmation instead
of on attribute itself. When rendering confirmation errors inline on the
form with form builders such as SimpleForm and Formtastic it is
confusing to the ender user to see the confirmation error message on the
attribute element. Instead it makes more sense to have this validation
error render on the confirmation field instead.

The i18n message has been updated for the confirmation validator error
message to include the original attribute name.
fcc534e
@bcardarella
Contributor

Think about it this way, when I type in my password and it doesn't match the confirmation the error message should render on the password_confirmation field instead of the password field. Every other web app not using Rails does it this way. I believe users expect this behavior and Rails (IMO) does it backwards.

@shedd
shedd commented Apr 23, 2012

+1

@CodeOfficer

+1, this makes too much sense

@jamesarosen
Contributor

+1

@rafaelfranca
Member

I agree with this. Let we see what the core team have to say.

@Aupajo
Aupajo commented Apr 23, 2012

+1

@coryschires

+1

@bcardarella
Contributor

Small update to the changelog in hope that core will accept the PR

@rafaelfranca rafaelfranca and 1 other commented on an outdated diff Apr 24, 2012
activemodel/CHANGELOG.md
@@ -6,6 +6,8 @@
* Trim down Active Model API by removing `valid?` and `errors.full_messages` *José Valim*
+* `ConfirmationValidator` error messages will attach to `:#{attribute}_confirmation` instead of `attribute` *Brian Cardarella*
@rafaelfranca
rafaelfranca Apr 24, 2012 Member

Put the changelog entry at the top of the list

@bcardarella
bcardarella Apr 24, 2012 Contributor

Whoops, sorry. I'll fix.

@amrnt
Contributor
amrnt commented Apr 24, 2012

+1

@chloerei

👍

@josevalim
Member

I am fine with this change but the reason given (simple form and formtastic use cases) is not enough for such abrupt change of behavior. That said, I would rather add a new option to confirmation's validator rather than changing it by default.

@bcardarella
Contributor

The SimpleForm and Formtastic use cases are just examples of it manifesting. The current way the error is attaching is basically saying that the attribute doesn't match the confirmation. It should be that the confirmation doesn't match the attribute. (which is the behavior that this patch gives) I am resistant to an option on the validator as I think the proper behavior is as I submitted in the PR.

As far as an abrupt change, this is only meant for the master branch which will be a major version release so I think abrupt changes should be implied.

@bcardarella
Contributor

In addition, this PR shouldn't introduce any functional changes to the any applications that would be upgrading. The confirmation validator still works just the same, the only difference is which attribute the error message is attached to and the default error message. Any upgrade challenges should be pretty minimal.

@josevalim
Member

Another issue with this PR (unless I am missing something) is that the attribute does not get translated before sent to I18n, so it will end up showing the attribute name in english when my locale is portuguese.

@bcardarella
Contributor

@josevalim ah, good point. I can update to cover that case.

@bcardarella
Contributor

@josevalim done

@abhijeetmisra

+1 for confirmation

@coorasse

+1

@bcardarella
Contributor

@josevalim is there any additional feedback on this? I'm happy to tackle any blockers

@steveklabnik
Member

👍, though this does break behavior. I'm not sure what the policy is about that re:rails 4.

@isaacsanders isaacsanders commented on the diff Apr 29, 2012
activemodel/lib/active_model/locale/en.yml
@@ -9,7 +9,7 @@ en:
inclusion: "is not included in the list"
exclusion: "is reserved"
invalid: "is invalid"
- confirmation: "doesn't match confirmation"
+ confirmation: "doesn't match %{attribute}"
@isaacsanders
isaacsanders Apr 29, 2012 Contributor

Is this right? I mean the %{}. Should it be #{}?

@isaacsanders
isaacsanders Apr 29, 2012 Contributor

okay. Just checking :D

@carlosantoniodasilva
carlosantoniodasilva Apr 29, 2012 Member

No problem, always good to have code review ;)

@tenderlove tenderlove merged commit f975a86 into rails:master Apr 29, 2012
@bcardarella
Contributor

@tenderlove awesome!

@josevalim
Member

This change needs to be added to the Upgrade to Rails 4 Guide.

@bcardarella
Contributor
@josevalim
Member

Awesome, tks!

@Dinuz
Dinuz commented Sep 5, 2012

Hi everybody,
I don't get it, my rails version is the 3.2.8 (and I saw that this change are implemented in it), but still using the client_side_validation gem (of @bcardarella ), with simple_form and twitter bootstrap, it attach the not matching confirmation error to the password field instead of the confirmation field.

What is wrong?

@rafaelfranca
Member

@Dinuz it is only implemented at master branch (4.0.0)

@Dinuz
Dinuz commented Sep 5, 2012

Oh oh....well than that is the issue (but the changes are present in the version 3.2.8., I just checked or I am wrong in something?).

Thanks anyway @rafaelfranca

@bcardarella
Contributor

@Dinuz the changes are only supposed to be on master which is currently the development branch for Rails 4.0.

@Dinuz
Dinuz commented Sep 5, 2012

Yes Thanks....I saw!!!
I apologize, my mistake I was checking the master branch and not the local files on my machine of the 3.2.8 (I saw the changes, but that were obviously on the wrong release)...

My Mistake.

@rbudiharso rbudiharso pushed a commit to rbudiharso/rails-i18n that referenced this pull request Apr 15, 2014
@amatsuda @kuroda amatsuda + kuroda include attribute name in confirmation error message
this follows en.yml change in rails/rails@fcc534e

see: rails/rails#5942
d3dac51
@nanaya nanaya referenced this pull request in svenfuchs/rails-i18n Aug 23, 2014
Merged

Include attribute name in confirmation error message #480

@nanaya nanaya added a commit to nanaya/rails that referenced this pull request Aug 23, 2014
@nanaya nanaya Update documentation to match change in #5942 [ci skip] e57ad6d
@seuros seuros added a commit to seuros/django that referenced this pull request Aug 27, 2014
@nanaya @seuros nanaya + seuros Update documentation to match change in #5942 [ci skip] 00c00c1
@epidemian epidemian added a commit to epidemian/rails-i18n that referenced this pull request Sep 18, 2014
@epidemian epidemian Change confirmation error message for es-* locales
This follows the changes introduced in rails/rails#5942, but does not include the attribute name in the message because it reads weird and it would require adding an article, which in turn would require knowing the grammatical gender of the attribute. E.g., "no coincide con *la* contraseña" or "no coincide con *el* número de cuenta".
9f9c8a9
@epidemian epidemian referenced this pull request in svenfuchs/rails-i18n Sep 18, 2014
Merged

Change confirmation error message for es-* locales #488

@trungpham trungpham added a commit to trungpham/rails that referenced this pull request Sep 18, 2014
@nanaya @trungpham nanaya + trungpham Update documentation to match change in #5942 [ci skip] c8b1ada
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment