If there is an error with the submitted password on a form, then both the password and password confirmation text fields should be highlighted in red. The default seems to be to highlight only the password field. Any suggestions on how to correct that? Because rails magically handles the highlighting, I''m not sure how to intercept that. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
7stud --
2011-Jul-27 12:51 UTC
Re: rails 3.0.9 usability problem: password/confirmation highlighting
I can get some code to work in the view, but it makes the view pretty messy: views/users/new.htmt.erb: <h1>Sign up</h1> <%= form_for(@user) do |f| %> <%= render ''shared/error_messages'' %> <div class="field"> <%= f.label :name, "Name:"%> </div> <div> <%= f.text_field :name %> </div> <div class="field"> <%= f.label :email, "Email:" %> </div> <div> <%= f.text_field :email %> </div> <div class="field"> <%= f.label :password, "Password (at least 6 characters):" %> </div> <div> <%= f.password_field :password %> </div> <% password_error = false @user.errors.full_messages.any? do |error| if error.match /password/i password_error = true end end %> <% if password_error %> <div class="field_with_errors"> <% end %> <div class="field "> <%= f.label :password_confirmation, "Password confirmation:" %> </div> <div> <%= f.password_field :password_confirmation %> </div> <% if password_error %> </div> <% end %> <div class="actions"> <%= f.submit "Sign up" %> </div> <% end %> To move that code to a partial, is the solution to use @f in form_for()? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
7stud --
2011-Jul-27 14:23 UTC
Re: rails 3.0.9 usability problem: password/confirmation highlighting
This is what I did: views/users/new.html.erb: <h1>Sign up</h1> <%= form_for(@user) do |f| %> <% @f_for_partial = f %> <%= render ''shared/error_messages'' %> <div class="field"> <%= f.label :name, "Name:"%> </div> <div> <%= f.text_field :name %> </div> <div class="field"> <%= f.label :email, "Email:" %> </div> <div> <%= f.text_field :email %> </div> <div class="field"> <%= f.label :password, "Password (at least 6 characters):" %> </div> <div> <%= f.password_field :password %> </div> <%= render ''users/password_confirmation_fix'' %> <div class="actions"> <%= f.submit "Sign up" %> </div> <% end %> views/users/_password_confirmation_fix.html.erb: <% password_error = @user.errors.full_messages.any? do |error| error.match /password/i end %> <% if password_error %> <div class="field_with_errors"> <% end %> <div class="field "> <%= @f_for_partial.label :password_confirmation, "Password confirmation:" %> </div> <div> <%= @f_for_partial.password_field :password_confirmation %> </div> <% if password_error %> </div> <% end %> And in the action I did this: def create # POST requests to ''/users'' routes here @user = User.new(params[:user]) if @user.save flash[:success] = "Welcome to the website." redirect_to @user #goes to user ''show'' page else @title = ''Sign up'' #If password errors, then erase passwords. #If no password errors, redisplay passwords. if @user.errors.full_messages.any? {|error| error.match /password/i} @user.password = '''' @user.password_confirmation = '''' end render ''new'' end end -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.