Talking to myself here. I managed to work it out, but the number of 
lines of code convince me that I am swimming upstream here. Any 
recommendations for streamlining would be graciously accepted.

The following works, in a hackish sort of way:

var combo_box = function(e){
        var picker = $('o_s').innerHTML;
        if($F('o_s') = 'Add new...'){
                if($('o_s').replace('<input type="text" id="o_s" name="o_s" 
value="" 
/>')){
                        $('o_s').focus();
                        Event.observe('o_s','blur',function(e){
                                txt = Event.element(e);
                                if(txt.value = ''){
                                        new Insertion.After('o_s','<select 
id="o_s" name="o_s" size="1">' 
+ picker + '</select>');
                                        Event.observe('o_s','change',combo_box);
                                        txt.remove();
                                }
                        });
                }
        }
}
//inside an Event.observe(window...) call:
if($('o_s')){
        Event.observe('o_s','change',combo_box);
}

Thanks,

Walter

On Jul 6, 2007, at 1:54 PM, Walter Lee Davis wrote:

>
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to