I am successfully using Prototype replace() to dynamically replace a
select picker with a text field when the user chooses Add new... from
the bottom of the list. The behavior I would like to add to this is to
restore the original picker if the user blurs away from this new field.
From the API docs, the replace function is said to return a reference
to the object that was removed. Does this reference include all of the
original content?
Here's what I've tried:
if($('o_s')){
var picker;
Event.observe('o_s','change',function(e){
if($F('o_s') == 'Add new.'){
if(picker = $('o_s').replace('<input type="text"
id="o_s" name="o_s"
value="" />')){
$('o_s').focus();
Event.observe('o_s','blur',function(e){
if($F('o_s') == ''){
$('o_s').replace(picker)
}
});
}
}
});
}
I expect the newly-created text field to disappear when I leave it
empty and blur away from it. Instead, I see [object HTMLSelectElement]
appear AFTER the text field, not replacing it at all. I've tried
replacing the bare object reference with picker.nodeValue, but that
just gets me an error. Replace() needs an HTML string with the
replacement content, but I don't know how to get that out of the
object.
I can almost understand why this is happening, but it's not clear how
to work around it.
Any suggestions?
Thanks,
Walter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---