Scaffold Password Confirmation => no red border

Hi all,

i am using the normal rails error checking that comes with scaffold.
Now I a password_confirmation field in my form - which is not in my
database

the confirmation checking works perfect and a text will be shown in the
error box if the 2 password fields are not equal.
My problem is, that the border around the password_confirmation field
will not get red - when the password_confirmation field throws an error.

any idea - what I can do?

thanks for any help
Andreas

my code:

Password:

<%= password_field ‘user’, ‘password’,{ :maxlength => ‘16’, :size =>
‘30’, :class => ‘input’ } %>

Confirm Password:

<%= password_field ‘user’, ‘password_confirmation’, { :maxlength =>
‘16’, :size => ‘30’, :class => ‘input’ } %>

Andreas S. wrote:

Password:

<%= password_field ‘user’, ‘password’,{ :maxlength => ‘16’, :size =>
‘30’, :class => ‘input’ } %>

Confirm Password:

<%= password_field ‘user’, ‘password_confirmation’, { :maxlength =>
‘16’, :size => ‘30’, :class => ‘input’ } %>

View the html source of the generated html when an error is thrown and
write down “id” of the element that you want to color red and then edit
your .css accordingly.

(If you are using the scaffolding generator then most likely the .css
you are linking to is scaffold.css)

do you think it is a css problem? I dont think so.

when I look at my html output after an error in the field “password”, I
see this:

Password:

Confirm Password:

as you can see - rails did a div with the error box around my text field
from the password - but not at the password_confirmation field.

Ilan B. wrote:

Andreas S. wrote:

Password:

<%= password_field ‘user’, ‘password’,{ :maxlength => ‘16’, :size =>
‘30’, :class => ‘input’ } %>

Confirm Password:

<%= password_field ‘user’, ‘password_confirmation’, { :maxlength =>
‘16’, :size => ‘30’, :class => ‘input’ } %>

View the html source of the generated html when an error is thrown and
write down “id” of the element that you want to color red and then edit
your .css accordingly.

(If you are using the scaffolding generator then most likely the .css
you are linking to is scaffold.css)

well, I dont need to insert this
because I dont want a red border around my confirmation field - all the
time
only when an error occured

Ilan B. wrote:

Andreas S. wrote:

do you think it is a css problem? I dont think so.

please insert the following into your .css file and refresh:

#user_password_confirmation {
border: 2px solid red
}

ilan

On 2-nov-2006, at 14:55, Andreas S. wrote:

My problem is, that the border around the password_confirmation field
will not get red - when the password_confirmation field throws an
error.

any idea - what I can do?

Do you have a css tag for scaffold in your layout?

gr,
bartz

I think, you should check your layouts *.rhtml file. In the header must
be the following code:
<%= stylesheet_link_tag ‘scaffold’, :media => ‘all’ %>
(if you use scaffold.css)

If you use your owen .css -file, include following code:
.fieldWithErrors {
padding: 2px;
border: 2px solid red;
display: table;
}
(in to *.css file)

Andreas S. wrote:

do you think it is a css problem? I dont think so.

please insert the following into your .css file and refresh:

#user_password_confirmation {
border: 2px solid red
}

ilan

I’m having exactly the same problem

The link to the stylesheet is the layouts *.rhtml file and this:

.fieldWithErrors {
padding: 2px;
border: 2px solid red;
display: table;
}
is included in the stylesheet

But the borders around the fields with erros won’t go red

This is excactly what I hate on rails, all answers are different - and
none of them is working. You cant solve the problem - because I tap into
fog right now on a so easy thing that was done in asp in seconds. but
with the scaffold thing - I dont know whats going on in the background.

  1. yes, I use the scaffhold css
  2. yes, I inserted <%= stylesheet_link_tag ‘scaffold’, :media => ‘all’
    %>
  3. the field that is not red - is a field that is not in the database -
    it is a password_confirmation field. the error text is correct and the
    confirmation works
    <%= password_field ‘user’, ‘password_confirmation’, { :maxlength =>
    ‘16’, :size => ‘30’, :class => ‘input’ } %>
  4. my css class ‘input’ is ok - i use it on all other fields too

andreas

On 7 November 2006 13:18, Andreas S. wrote:

confirmation works
<%= password_field ‘user’, ‘password_confirmation’, { :maxlength =>
‘16’, :size => ‘30’, :class => ‘input’ } %>
4) my css class ‘input’ is ok - i use it on all other fields too

You see, it work like this:
If you use built-in form helpers (e.g. text_field helper), they check if
the
model instance for which you render that field has errors, and if so, it
will
wrap the generated field HTML in DIV with some class (fieldWithErrors,
but
I’m not sure).

Then, the validates_confirmation_of is designed to add validation error
for
the attribute itself, not it’s “_confirmation” brother (e.g. for
“password”,
not for “password_confirmation”).

So, when text_field for password_confirmation is produced, it find no
errors
for that field, so no “red border” is displayed around that field.

The same problems I had long ago, when I designed validation for
associated
objects. E.g. Product should have a Category associated. I used to write
class Product < ActiveRecord::Base
belongs_to :category
validates_presence_of :category
end

In the product edit I used to create a select for category_id attribute
which
didn’t outlined this select if there was no category specified. The
right
solution was to do “validates_presence_of :category_id” (and then, if
you
wish to, do “validates_associated :category”).

Solutions are:

  1. Leave everything as it is. Actually, It could be a problem with
    password
    field, not with password_confirmation field.
  2. Design new validation that will check if attributes are equal and add
    error
    to password_confirmation instead of password.
  3. Design a custom text_field helper for “password_confirmation”, that
    will
    check if “password” field has errors and outline itself then.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs