AutoComplete functionality

247 views
Skip to first unread message

Michael Strecke

unread,
Feb 28, 2011, 6:38:58 AM2/28/11
to lif...@googlegroups.com
Hi,

perhaps someone know the answer for the following two questions. Google
was not that helpful.
I'm using Lift 2.1/Scala 2.8.0

I have the AutoComplete widget running:

import _root_.net.liftweb.widgets.autocomplete._
...
bind(....
"foobar" -> Autocomplete(start, options, onSubmit),
...

The suggestions from "options" pop up when I type into the text field.

Question 1:
How do I clear the field in a way that the onSubmit function does not
return the latest value selected from the drop down list?

When I first select a value from the drop down list, I can use the
delete key or a space bar to empty the input field. However, the
onSubmit function still returns the value from the drop down list.

Perhaps one of the jsonOptions? The only one that caught my eye
"mustMatch" is already set to "false" be default...


Question 2:
Ajax elements usually call a Lift function (to emit a JsCmd) when a
change occurs. Is there something similar for the AutoComplete widget?

Thanks


Michael

Sergey Andreev

unread,
Mar 1, 2011, 9:02:18 AM3/1/11
to lif...@googlegroups.com
Hi Michael,

Question 1:

You need to modify the AutoComplete widget's source code and add handlers for onBlur/keypress events so that they will change the value of the hidden field appropriately.

Question 2:

Yes, AutoComplete uses JQuery AutoComplete plugin which makes ajax calls to the server.

Best regards,
Sergey




--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.


Michael Strecke

unread,
Mar 2, 2011, 5:10:04 AM3/2/11
to lif...@googlegroups.com
Hi Sergey,

Am 01.03.2011 15:02, schrieb Sergey Andreev:
> Hi Michael,
>
> Question 1:
>
> You need to modify the AutoComplete widget's source code and add
> handlers for onBlur/keypress events so that they will change the value
> of the hidden field appropriately.

Thanks.

I have no idea how to do that. But that hasn't stopped me before, so I
had a look at the source code.

I found the place where the JQuery calls and the input fields are
generated.
I presume that an onBlur event handler can be inserted in a similar way
as shown in SHtml.scala with the areaText_* function.
But I am at a loss on how to change the hidden field value. I'm not
familiar with the inner workings of JavaScript.


I can confirm that behaviour in also present in Lift 2.2.


I think one might call it a bug, because it is also responsible for the
following "unexpected" behaviour of the widget:

If you enter text in the autocomplete text field without ever touching
the drop down list, the entered value is NOT returned to the
application. It does not matter if the entered value is part of the drop
down list or not.

It seems that the hidden field is ONLY updated if a list entry is
selected. Any manual entries into the text field are ignored.

>
> Question 2:
>
> Yes, AutoComplete uses JQuery AutoComplete plugin which makes ajax
> calls to the server.

Sorry, I rephrase.

I'm aware that the AutoComplete plugin uses ajax calls to populate the
drop down list. I was wondering if an event is fired when a selection
had occurred (but before the form is submitted).

A use case could be: The user selects an article from the drop down list
and additional information is displayed (using DisplayMessage or
similar) before the form is submitted.

Kind regards


Michael


>
>
> On Mon, Feb 28, 2011 at 12:38 PM, Michael Strecke
> <michael...@googlemail.com

> <mailto:lif...@googlegroups.com>.


> To unsubscribe from this group, send email to
> liftweb+u...@googlegroups.com

> <mailto:liftweb%2Bunsu...@googlegroups.com>.

Sergey Andreev

unread,
Mar 2, 2011, 5:30:52 AM3/2/11
to lif...@googlegroups.com
Hi Michael,

As far as i understand the AutoComplete widget is not a top priority right now so all you can do is to hack around the existing widget. 

You can use something like that for blur (onkeypress) events to update hidden field:

jQuery(#textFieldId).bind("blur", function() {
  jQuery(#hiddenFieldId).val(jQuery(#textFieldId).val());
});

jQuery AutoComplete fires events when you type the text. This events are handled using options function on the AutoComplete widget. Unfortunately the server call should return a list of strings so i am not sure if you can display additional information.

Best regards,
Sergey

Michael Strecke

unread,
Mar 2, 2011, 7:00:08 PM3/2/11
to lif...@googlegroups.com
Hi Sergey,

thank you for the info. I managed to modify the AutoComplete class to
implement your solution (the "onLoad2" parts below).

I'm not sure, if onLoad and onLoad2 can be merged somehow, but it does
work this way.

Even though the AutoComplete is not a top priority, I will open a
ticket. Perhaps the powers that be will pick it up if the solution is
presented on a silver platter.

Thank you for your help


Michael

val onLoad = JsRaw("""
jQuery(document).ready(function(){
var data = """+what.encJs+""";
jQuery("#"""+id+"""").autocomplete(data,
"""+autocompleteOptions.toJsCmd+""").result(function(event, dt, formatted) {
jQuery("#"""+hidden+"""").val(formatted);
});
});""")

val onLoad2 = JsRaw("""
jQuery(document).ready(function(){
jQuery("#"""+id+"""").bind("blur", function() {
jQuery("#"""+hidden+"""").val(jQuery("#"""+id+"""").val());
});
});""")

<span>
<head>
<link rel="stylesheet" href={"/" +
LiftRules.resourceServerPath +"/autocomplete/jquery.autocomplete.css"}
type="text/css" />
<script type="text/javascript" src={"/" +
LiftRules.resourceServerPath +"/autocomplete/jquery.autocomplete.js"} />
{Script(onLoad)}
{Script(onLoad2)}
</head>

Am 02.03.2011 11:30, schrieb Sergey Andreev:
> Hi Michael,
>

> As far as i understand the AutoComplete widget is not a top priority
> right now so all you can do is to hack around the existing widget.
>
> You can use something like that for blur (onkeypress) events to update
> hidden field:
>
> jQuery(#textFieldId).bind("blur", function() {
> jQuery(#hiddenFieldId).val(jQuery(#textFieldId).val());
> });
>
> jQuery AutoComplete fires events when you type the text. This events
> are handled using options function on the AutoComplete widget.
> Unfortunately the server call should return a list of strings so i am
> not sure if you can display additional information.
>
> Best regards,
> Sergey
>
> On Wed, Mar 2, 2011 at 11:10 AM, Michael Strecke
> <michael...@googlemail.com

> > <mailto:michael...@googlemail.com

> > <mailto:lif...@googlegroups.com


> <mailto:lif...@googlegroups.com>>.
> > To unsubscribe from this group, send email to
> > liftweb+u...@googlegroups.com
> <mailto:liftweb%2Bunsu...@googlegroups.com>

> > <mailto:liftweb%2Bunsu...@googlegroups.com
> <mailto:liftweb%252Buns...@googlegroups.com>>.

Michael Strecke

unread,
Mar 2, 2011, 8:03:05 PM3/2/11
to lif...@googlegroups.com
Am 03.03.2011 01:00, schrieb Michael Strecke:
> Even though the AutoComplete is not a top priority, I will open a
> ticket. Perhaps the powers that be will pick it up if the solution is
> presented on a silver platter.
>
Well, I'm not the only one with the problem. A ticket was already added
a few days ago...

https://www.assembla.com/spaces/liftweb/tickets/892-autocomplete%28%29-should-have-option-to-allow-user-to-enter-their-own-value

I've attached a patch against 2.2-final - only 8 lines... if someone is
listening

Thanks again for your help Sergey.

Michael

autocomplete_onblur.diff

David Pollak

unread,
Mar 2, 2011, 8:23:24 PM3/2/11
to lif...@googlegroups.com

This kind of statement is not welcome in the Lift community.  Please see http://liftweb.net/community

Being polite will get you what you want a lot faster than not being polite.
 

Thanks again for your help Sergey.

Michael

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.




--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Blog: http://goodstuff.im
Surf the harmonics

Michael Strecke

unread,
Mar 3, 2011, 5:27:43 AM3/3/11
to lif...@googlegroups.com, feeder.of...@gmail.com
Oops,

I'm sorry, if my wording is misleading.

It was not my intention to be rude.

I should have used more smilies or mark it with an <irony> tag.

Nevertheless - presenting a solution and creating a patch will speed up things, right? :-) ;-)

Michael

Andreas Joseph Krogh

unread,
Mar 3, 2011, 6:00:05 AM3/3/11
to lif...@googlegroups.com
On Thu, Mar 3, 2011 at 2:23 AM, David Pollak <feeder.of...@gmail.com> wrote:


On Wed, Mar 2, 2011 at 5:03 PM, Michael Strecke <michael...@googlemail.com> wrote:
Am 03.03.2011 01:00, schrieb Michael Strecke:
> Even though the AutoComplete is not a top priority, I will open a
> ticket. Perhaps the powers that be will pick it up if the solution is
> presented on a silver platter.
>
Well, I'm not the only one with the problem. A ticket was already added
a few days ago...

https://www.assembla.com/spaces/liftweb/tickets/892-autocomplete%28%29-should-have-option-to-allow-user-to-enter-their-own-value

I've attached a patch against 2.2-final - only 8 lines... if someone is
listening

This kind of statement is not welcome in the Lift community.  Please see http://liftweb.net/community

Being polite will get you what you want a lot faster than not being polite.

Hm, this conversation comes to mind:

On 02/22/2011 04:28 PM, David Pollak wrote:
> On Tue, Feb 22, 2011 at 7:23 AM, mnotes <sergey....@stonybrook.edu>wrote:
>
>> Dear David,
>> I am sorry if I have wasted any of your time. But I am an expert in
>> systems behavior.
>
>
> No, as far as I can tell, you're a complete idiot.  Please go away.

Now, Mr. Pollak; How does "you're a complete idiot" comply with these statements you just referred to:
  • You can disagree with a person's opinion, but please continue to respect the person
  • You may have to agree to disagree
Everyone can get upset sometimes...

--
Andreas Joseph Krogh <and...@officenet.no>
Senior Software Developer / CTO
Public key: http://home.officenet.no/~andreak/public_key.asc
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Rosenholmveien 25       | know how to do a thing and to watch         |
1414 Trollåsen          | somebody else doing it wrong, without       |
NORWAY                  | comment.                                    |
Org.nr: NO 981 479 076  |                                             |
                        |                                             |
Tlf:    +47 24 15 38 90 |                                             |
Fax:    +47 24 15 38 91 |                                             |
Mobile: +47 909  56 963 |                                             |
------------------------+---------------------------------------------+

David Pollak

unread,
Mar 3, 2011, 7:59:27 AM3/3/11
to lif...@googlegroups.com
On Thu, Mar 3, 2011 at 2:27 AM, Michael Strecke <michael...@googlemail.com> wrote:
Oops,

I'm sorry, if my wording is misleading.

It was not my intention to be rude.

I should have used more smilies or mark it with an <irony> tag.

Nevertheless - presenting a solution and creating a patch will speed up things, right? :-) ;-)

Actually, a patch will not speed things up.  Once again, please read the community link.  We do not accept IP into Lift unless it's done by one of the committers.

This particular issue is not a high priority.  If you want to disseminate a better autocomplete widget, you're welcome to,  At this point, I don't know of a committer who has time to work on the issue and make the kind of improvements to the autocomplete widget... and it needs far more work than a simple patch or two.
 
 

Jeppe Nejsum Madsen

unread,
Mar 3, 2011, 8:21:26 AM3/3/11
to lif...@googlegroups.com
On Thu, Mar 3, 2011 at 1:59 PM, David Pollak
<feeder.of...@gmail.com> wrote:
>
>
> On Thu, Mar 3, 2011 at 2:27 AM, Michael Strecke
> <michael...@googlemail.com> wrote:
>>
>> Oops,
>>
>> I'm sorry, if my wording is misleading.
>>
>> It was not my intention to be rude.
>>
>> I should have used more smilies or mark it with an <irony> tag.
>>
>> Nevertheless - presenting a solution and creating a patch will speed up
>> things, right? :-) ;-)
>
> Actually, a patch will not speed things up.  Once again, please read the
> community link.  We do not accept IP into Lift unless it's done by one of
> the committers.
>
> This particular issue is not a high priority.  If you want to disseminate a
> better autocomplete widget, you're welcome to,  At this point, I don't know
> of a committer who has time to work on the issue and make the kind of
> improvements to the autocomplete widget... and it needs far more work than a
> simple patch or two.

But as you (Michael, not David :-) may have seen there's a Lift
Modules initiative under way which should make it easier to contribute
something that is not in core Lift. I think a rewritten autocomplete
widget would fit this nicely....

Search the list or ask if you need more details....

/Jeppe

David Pollak

unread,
Mar 3, 2011, 8:23:55 AM3/3/11
to lif...@googlegroups.com

First, until you've demonstrated long-standing contribution to this community, you are in no position to school other long standing members on their behavior in this forum.

Second, this forum reflects my long-standing efforts to make sure it is a polite, helpful place and the quality of the community reflects that... along with the almost 8,000 posts I've made to this list.

Third, I stand by my statement.  The poster is the 4th person in the last 4 years who has been banned from the community for inappropriate behavior.  Not only was he just looking for a fight, but he has a PhD in a hard science and is an associate professor at a well respected university.  Based on this, he has the skills to do real analysis and real discussion about a topic.  Instead, he chose to ignore or dismiss the questions and feedback on the topic (e.g., issues related to caching, jvm configuration, what kind of conditions are being simulated in a benchmark).  This, in my opinion, make him an idiot based on the definition, "An idiot ... is ... someone who acts in a self-defeating or significantly counterproductive way." (See http://en.wikipedia.org/wiki/Idiot).  Put another way, he received significantly more respect for this community than he demonstrated towards it.
 

--
Andreas Joseph Krogh <and...@officenet.no>
Senior Software Developer / CTO
Public key: http://home.officenet.no/~andreak/public_key.asc
------------------------+---------------------------------------------+
OfficeNet AS            | The most difficult thing in the world is to |
Rosenholmveien 25       | know how to do a thing and to watch         |
1414 Trollåsen          | somebody else doing it wrong, without       |
NORWAY                  | comment.                                    |
Org.nr: NO 981 479 076  |                                             |
                        |                                             |
Tlf:    +47 24 15 38 90 |                                             |
Fax:    +47 24 15 38 91 |                                             |
Mobile: +47 909  56 963 |                                             |
------------------------+---------------------------------------------+

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.

Stefan Langer

unread,
Mar 3, 2011, 8:44:35 AM3/3/11
to lif...@googlegroups.com
What does IP mean in this context?

2011/3/3 David Pollak <feeder.of...@gmail.com>:

David Pollak

unread,
Mar 3, 2011, 8:50:46 AM3/3/11
to lif...@googlegroups.com
On Thu, Mar 3, 2011 at 5:44 AM, Stefan Langer <mailto...@googlemail.com> wrote:
What does IP mean in this context?

Intellectual Property.  It means that there's a clear provenance of all the code in Lift, who owns it, how they contributed it, etc.  The provenance of the code is important for corporate users of open source... they have make sure they will not sued by a copyright holder who alleges that some openly available package contains their works.  The highest profile case like this was the SCO vs. Linux issue, but it has happened in other instances.
 

Andreas Joseph Krogh

unread,
Mar 3, 2011, 2:10:42 PM3/3/11
to lif...@googlegroups.com
>> Now, Mr. Pollak; How does "*you're a complete idiot*" comply with these

>> statements you just referred to:
>>
>> - You can disagree with a person's opinion, but please continue to
>> respect the person
>> - You may have to agree to disagree

>>
>> Everyone can get upset sometimes...
>>
>
> First, until you've demonstrated long-standing contribution to this
> community, you are in no position to school other long standing members on
> their behavior in this forum.
>
> Second, this forum reflects my long-standing efforts to make sure it is a
> polite, helpful place and the quality of the community reflects that...
> along with the almost 8,000 posts I've made to this list.
>
> Third, I stand by my statement. The poster is the 4th person in the last 4
> years who has been banned from the community for inappropriate behavior.
> Not only was he just looking for a fight, but he has a PhD in a hard science
> and is an associate professor at a well respected university. Based on
> this, he has the skills to do real analysis and real discussion about a
> topic. Instead, he chose to ignore or dismiss the questions and feedback on
> the topic (e.g., issues related to caching, jvm configuration, what kind of
> conditions are being simulated in a benchmark). This, in my opinion, make
> him an idiot based on the definition, "An idiot ... is ... someone who acts
> in a self-defeating or significantly counterproductive way." (See
> http://en.wikipedia.org/wiki/Idiot). Put another way, he received
> significantly more respect for this community than he demonstrated towards
> it.

I'm observing and reflecting upon what I observe. I think you've done a
fantastic job with both Lift and this community.

--
Andreas Joseph Krogh <and...@officenet.no>
Senior Software Developer / CTO
Public key: http://home.officenet.no/~andreak/public_key.asc
------------------------+---------------------------------------------+
OfficeNet AS | The most difficult thing in the world is to |
Rosenholmveien 25 | know how to do a thing and to watch |

1414 Troll�sen | somebody else doing it wrong, without |

Reply all
Reply to author
Forward
0 new messages