Sure, this is my (modified) code using one of the ruby helpers, but
it's pretty straight forward to convert to JS only...
text_field_with_auto_complete :search, :data, {},
:after_update_element => <<-JS
function (field, element) {
field.value = field.value.replace(/^\s*|\s*$/g, '')
}
JS
"field" is the text input element and "element" here is the selected LI.
If you put the code between quotes then just escape the various pieces
of the regex and you're good to go.
Andrew
On 5/23/06, Daniel Elmore <[EMAIL PROTECTED]> wrote:
Good idea, can you show me how you did that?
Daniel Elmore
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Andrew
Kaspick
Sent: Tuesday, May 23, 2006 4:00 PM
To: [email protected]
Subject: Re: [Rails-spinoffs] script.aculo.us AutoComplete Woes
For now, I've used the afterUpdateElement callback to strip the
whitespace using the code you provided and it works great now.
Now I don't need to migrate the change to any future scriptaculous releases.
Thanks for the pointers.
On 5/23/06, Daniel Elmore <[EMAIL PROTECTED]> wrote:
> If you look at the ajax response content on the demo site, you won't find
> any spaces in the markup. This is obviously harder to avoid if you're
using
> some middleware to build your response data.
>
> Daniel Elmore
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Andrew
> Kaspick
> Sent: Tuesday, May 23, 2006 3:36 PM
> To: [email protected]
> Subject: Re: [Rails-spinoffs] script.aculo.us AutoComplete Woes
>
> Yeah, I was looking into that too, but thought that I must be doing
> something wrong since the customized autocomplete demo on the
> scriptaculous site seems to trim the space somehow.
>
> Thanks though, I'll try making the change you suggested.
>
> On 5/23/06, Daniel Elmore <[EMAIL PROTECTED]> wrote:
> > I had to modify the updateElement method to trim the spaces.
> >
> > Change this:
> > this.element.value = value;
> >
> > To this:
> > this.element.value = value.replace(/^\s*|\s*$/g,"");
> >
> >
> > Not sure why that wouldn't be there already.
> >
> > Daniel Elmore
> >
> >
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of
Andrew
> > Kaspick
> > Sent: Tuesday, May 23, 2006 3:14 PM
> > To: [email protected]
> > Subject: Re: [Rails-spinoffs] script.aculo.us AutoComplete Woes
> >
> > I have used the informal class on my own stuff (which works), but when
> > I select an item, some whitespace is added before the selected text.
> > It actually appears to be newlines that are being inserted into the
> > textfield.
> >
> > Any ideas what may be causing this? Would this occur because of extra
> > spacing in the markup I'm sending back from the server? I tried
> > removing some, but it didn't seem to have an affect.
> >
> > Thanks
> >
> > On 12/6/05, Daniel Elmore <[EMAIL PROTECTED]> wrote:
> > > Good! Thank you, that works!
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: [EMAIL PROTECTED]
> > > [mailto:[EMAIL PROTECTED] On Behalf Of Cam
> > > McVey
> > > Sent: Tuesday, December 06, 2005 4:10 AM
> > > To: [email protected]
> > > Subject: Re: [Rails-spinoffs] script.aculo.us AutoComplete Woes
> > >
> > > Hi Daniel,
> > >
> > > You have to wrap up anything you DON'T want to appear in the text box
> > > in a span tag with a class of 'informal'. For example:
> > >
> > > [ul]
> > > [li]John Smith<br />[span
class="informal"[EMAIL PROTECTED]/span][/li]
> > > [/ul]
> > >
> > > Regards,
> > > Cam
> > >
> > > On 12/6/05, Daniel Elmore <[EMAIL PROTECTED]> wrote:
> > > > I was wondering if someone could help me with an autocomplete
problem.
> > > I
> > > > have the autocomplete div receiving a <UL> that looks like:
> > > >
> > > > <ul>
> > > > <li>Name<br>Email</li>
> > > > </ul>
> > > >
> > > > When the user hits enter and the value is filled into the text field
> > > > it's putting both the name and email in the field. I just want the
> > > name.
> > > <snip>
> > >
> > > _______________________________________________
> > > Rails-spinoffs mailing list
> > > [email protected]
> > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
> > >
> > _______________________________________________
> > Rails-spinoffs mailing list
> > [email protected]
> > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
> >
> > _______________________________________________
> > Rails-spinoffs mailing list
> > [email protected]
> > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
> >
> _______________________________________________
> Rails-spinoffs mailing list
> [email protected]
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>
> _______________________________________________
> Rails-spinoffs mailing list
> [email protected]
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs