[ 
https://issues.apache.org/jira/browse/WICKET-1736?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Igor Vaynberg reassigned WICKET-1736:
-------------------------------------

    Assignee: Igor Vaynberg

> Allow Access to AutoCompleteTextField AutoCompleteBehavior
> ----------------------------------------------------------
>
>                 Key: WICKET-1736
>                 URL: https://issues.apache.org/jira/browse/WICKET-1736
>             Project: Wicket
>          Issue Type: Bug
>          Components: wicket
>    Affects Versions: 1.3.4, 1.4-M2
>         Environment: N/A
>            Reporter: Will Hoover
>            Assignee: Igor Vaynberg
>
> Currently there is no easy way to access the AutoCompleteBehavior of the 
> AutoCompleteTextField. This is useful when dynamically enabling/disabling the 
> behavior (among other reasons). 
> The current code is:
> {code}
>       public AutoCompleteTextField(String id, IModel model, Class type,
>               IAutoCompleteRenderer renderer, AutoCompleteSettings settings)
>       {
>               super(id, model, type);
>               // this disables Firefox autocomplete
>               add(new SimpleAttributeModifier("autocomplete", "off"));
>               add(new AutoCompleteBehavior(renderer, settings)
>               {
>                       private static final long serialVersionUID = 1L;
>                       protected Iterator getChoices(String input)
>                       {
>                               return 
> AutoCompleteTextField.this.getChoices(input);
>                       }
>               });
>       }
> {code}
> One solution to this is to extract the creation of the AutoCompleteBehavior 
> to a method:
> {code}
>       public AutoCompleteTextField(final String id, final IModel model, final 
> Class<?> type, final IAutoCompleteRenderer renderer, final 
> AutoCompleteSettings settings) {
>               super(id, model, type);
>               // this disables Firefox autocomplete
>               add(new SimpleAttributeModifier("autocomplete", "off"));
>               final AutoCompleteBehavior autoCompleteBehavior = 
> createAutoCompleteBehavior(renderer, settings);
>               if (autoCompleteBehavior == null) {
>                       throw new NullPointerException("Auto complete behavior 
> cannot be null");
>               }
>               add(autoCompleteBehavior);
>       }
>       protected AutoCompleteChoiceBehavior createAutoCompleteBehavior(final 
> IAutoCompleteRenderer renderer, final AutoCompleteSettings settings) {
>               return new AutoCompleteChoiceBehavior(renderer, settings);
>       }
>       public class AutoCompleteChoiceBehavior extends AutoCompleteBehavior {
>               public AutoCompleteChoiceBehavior(final IAutoCompleteRenderer 
> renderer, final AutoCompleteSettings settings) {
>                       super(renderer, settings);
>               }
>               protected final Iterator<?> getChoices(final String input) {
>                       return 
> AbstractAutoCompleteTextField.this.getChoices(input);
>               }
>       }
> {code}
> Also, when the auto-complete behavior is disabled [overriding the 
> isEnable(component)] it currently does not clear the client events from the 
> text field. A work around for this is to clear it out onCompoentTag (not the 
> best option, but it works):
> {code}
>       protected void onComponentTag(final ComponentTag tag) {
>               if (!getAutoCompleteBehavior().isEnabled(this)) {
>                       // FIXME : Need to clear the events when the 
> auto-complete behavior is disabled
>                       tag.put("onfocus", 
> "this.onblur=null;this.onchange=null;this.onkeydown=null;this.onkeypress=null;this.onkeyup=null;");
>               }
>               super.onComponentTag(tag);
>       }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to