How to force user to select from AutoComplete choices

2013-04-16 Thread heikki
hello,

I've an autocomplete textfield (this one:
com.googlecode.wicket.jquery.ui.form.autocomplete.AutoCompleteTextField) and
I'd like to restrict users to select one of the values presented in its
choices. 

As it is, you can also input values that are not in the choices.

Is there an easy way to do this ?

Kind regards
Heikki Doeleman



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/How-to-force-user-to-select-from-AutoComplete-choices-tp4658033.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: How to force user to select from AutoComplete choices

2013-04-16 Thread Igor Vaynberg
you can try using this:

https://github.com/ivaynberg/wicket-select2

-igor

On Tue, Apr 16, 2013 at 8:30 AM, heikki tropic...@gmail.com wrote:
 hello,

 I've an autocomplete textfield (this one:
 com.googlecode.wicket.jquery.ui.form.autocomplete.AutoCompleteTextField) and
 I'd like to restrict users to select one of the values presented in its
 choices.

 As it is, you can also input values that are not in the choices.

 Is there an easy way to do this ?

 Kind regards
 Heikki Doeleman



 --
 View this message in context: 
 http://apache-wicket.1842946.n4.nabble.com/How-to-force-user-to-select-from-AutoComplete-choices-tp4658033.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: How to force user to select from AutoComplete choices

2013-04-16 Thread Sebastien
Hi Heikki,

Basically the AutoCompleteTextField is a TextField, so you can cannot
restrict - strictly speaking - the user choice like you can do with a
DropDownChoice/DropDownList for instance...

However...
If the ACTF choice list is *type of String*, you can validate the user
choice, and report an error if the choice is not part of the list:

form.add(autocomplete.setRequired(true).add(new
IValidatorString() {

private static final long serialVersionUID = 1L;

@Override
public void validate(IValidatableString validatable) {

//TODO: customize the validation process here:
if (!MY_LIST.contains(validatable.getValue())) {
validatable.error(new ValidationError(not a valid
choice!));
}
}
}));

Second option: If the ACTF choice list is *type of beans*, then you can
check whether the modelobject is null in form#onSubmit. But as it is a
little bit late in the form processing (the components and form validation
already succeed) , prefer the option #1 if you can

Hope this helps,
Sebastien.



On Tue, Apr 16, 2013 at 5:36 PM, Igor Vaynberg igor.vaynb...@gmail.comwrote:

 you can try using this:

 https://github.com/ivaynberg/wicket-select2

 -igor

 On Tue, Apr 16, 2013 at 8:30 AM, heikki tropic...@gmail.com wrote:
  hello,
 
  I've an autocomplete textfield (this one:
  com.googlecode.wicket.jquery.ui.form.autocomplete.AutoCompleteTextField)
 and
  I'd like to restrict users to select one of the values presented in its
  choices.
 
  As it is, you can also input values that are not in the choices.
 
  Is there an easy way to do this ?
 
  Kind regards
  Heikki Doeleman
 
 
 
  --
  View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/How-to-force-user-to-select-from-AutoComplete-choices-tp4658033.html
  Sent from the Users forum mailing list archive at Nabble.com.
 
  -
  To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
  For additional commands, e-mail: users-h...@wicket.apache.org
 

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




Re: How to force user to select from AutoComplete choices

2013-04-16 Thread heikki
thanks for your replies,

@Igor : trying it, however when loading the page I get: TypeError:
$(...).select2 is not a function. Can you give some instruction as how to
wire things together? From the wicket-select2-examples, it is not obvious to
me where any JS gets included.

@Sebastien: sure, a validator can refuse input (doesn't even need to be a
String I guess?), but that is also too late (after you already put in a free
text value and submitted). I'm looking for a way to prevent unwanted input
client-side; the validator will be there as last resort server-side.



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/How-to-force-user-to-select-from-AutoComplete-choices-tp4658033p4658041.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: How to force user to select from AutoComplete choices

2013-04-16 Thread Sebastien
Hi,

Just to answer... your answer: the ACTF can work either with String type or
beans. Sure, the user enters a String but the ACTF is using the internal
converter (the class type should have been provided in the ctor) to
retrieve the bean reference back (from the previous choice list).

About your use case, I think Igor's wicket-select2 is the best choice...

Best regards,
Sebastien.


On Tue, Apr 16, 2013 at 7:16 PM, heikki tropic...@gmail.com wrote:

 thanks for your replies,

 @Igor : trying it, however when loading the page I get: TypeError:
 $(...).select2 is not a function. Can you give some instruction as how to
 wire things together? From the wicket-select2-examples, it is not obvious
 to
 me where any JS gets included.

 @Sebastien: sure, a validator can refuse input (doesn't even need to be a
 String I guess?), but that is also too late (after you already put in a
 free
 text value and submitted). I'm looking for a way to prevent unwanted input
 client-side; the validator will be there as last resort server-side.



 --
 View this message in context:
 http://apache-wicket.1842946.n4.nabble.com/How-to-force-user-to-select-from-AutoComplete-choices-tp4658033p4658041.html
 Sent from the Users forum mailing list archive at Nabble.com.

 -
 To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
 For additional commands, e-mail: users-h...@wicket.apache.org




Re: How to force user to select from AutoComplete choices

2013-04-16 Thread heikki
hi,

the js loading issue was apparently due to having both my own and a
select2-contributed jquery library in the same page. Solved.

This select2 solution does exactly what I was looking for, thanks !



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/How-to-force-user-to-select-from-AutoComplete-choices-tp4658033p4658049.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org