I want to have a text field that displays some text, but when the person
clicks that text field that text disapears but also, I want to switch
the type to a “password” field. I can do something close with straight
forward html:
It clears the text but does not change the type. I would like to use a
helper to do this and so far I have:
Can I do some kind of rjs helper to toggle the type? And is this even
possible? I realise that this is more of html question, but I would
rather use the helpers to get this done. Thanks all, and have a great
weekend,
Nope doesn’t work. what happens is that the text ‘Password is case
sensitive’ appears in the text box, then, as you click inside the text
box that text disapearse, which is what I want, but the text that is
entered after that is plain text, not ‘***’ as I would like in a
password field. Here is a modified version of the helper:
Alright, I got it! It’s totally a JavaScript solution and not a rails
solution but it works across FireFox and IE at least. Apperently only
IE7 allows the above examples to work correctly. So here it goes:
I ran into this a few weeks back. The Type attribute is protected under
IE once an element has been placed into the DOM. You can get around this
by creating a new password element using basic DOM methods:
o = document.getElementById(‘OLD_TEXT_ELEMENT_ID’)
d = document.createElement(‘INPUT’);
d.setAttribute(‘type’,‘password’);
d.value = o.value;
o.parentNode.replaceChild(a, o);
Alright, I got it! It’s totally a JavaScript solution and not a rails
solution but it works across FireFox and IE at least. Apperently only
IE7 allows the above examples to work correctly. So here it goes:
Alright, I got it! It’s totally a JavaScript solution and not a rails
solution but it works across FireFox and IE at least. Apperently only
IE7 allows the above examples to work correctly. So here it goes:
Wait a sec, what? I used your original example verbatim and it
worked fine with FireFox 2.0/Linux.
Regardless, doing this requires JavaScript, since it happens in
the client browser.
BTW, you could get away from duplicating fields in your markup
with something like this: