One tiny tweak that just occurred to me:
var combo = function(evt){
var elm = evt.element();
if ($F(elm) == 'Other...'){
var w = elm.getWidth() + 'px';
var theId = elm.id;
//following var should be all one line!
var txt = '<input type="text" name="' + elm.name + '" id="' +
theId
+ '" style="width:' + w + ';" />';
if(!window.comboBackup) window.comboBackup = new Object();
window.comboBackup.theId = elm.replace(txt);
$(theId).activate().observe('blur',function(e){
var t = e.element();
if($F(t) == t.defaultValue){
t.replace(window.comboBackup.theId);
$(theId).options.selectedIndex = 0;
}
});
}
}
$$('select.combo').invoke('observe','change',combo);
Now if you blur away from the form field without adding anything to
it, the old picker comes back to play. Can anyone recommend another
approach than stashing the old element in the window context?
Walter
On Apr 18, 2008, at 11:14 AM, Walter Lee Davis wrote:
>
> Sure.
>
> Make sure you have Prototype 1.6+ in your page, then add this in a
> script block/source:
>
> document.observe('dom:loaded',function(){
> var combo = function(evt){
> var elm = evt.element();
> if ($F(elm) == 'Other...'){
> var w = elm.getWidth() + 'px';
> var theId = elm.id;
> //following var should be all one line!
> var txt = '<input type="text" name="' + elm.name + '"
> id="' +
> theId + '" style="width:' + w + ';" />';
> elm.replace(txt);
> $(theId).activate();
> }
> }
> //this line applies it to all select boxes on the page that have the
> combo class
> $$('select.combo').invoke('observe','change',combo);
> });
>
>
> Now all you need to do is add the className 'combo' to your selects
> that you want to behave this way, and the option 'Other...' somewhere
> in the select list (I like the bottom, so they have to scan the
> list), and you're good to go.
>
> Walter
>
> On Apr 18, 2008, at 10:39 AM, [EMAIL PROTECTED] wrote:
>
>> martinevans sent you the following message:
>>
>> ====================================
>> Hi I'm looking for a combobox that can have text added looking at a
>> previous post you made
>>
>> "I've done a sort of cheater's combo box before with Prototype. All I
>> do is add an option to the end of a regular select that reads Add
>> new..., and then if that gets selected, I replace the entire select
>> with a same-name text input box. It's very simple. Let me know if you
>> want it and I'll dig out the code"
>>
>> Would it be possible to send me a copy of your code please
>> thanks
>> Martin
>> ====================================
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---