Wicket
  1. Wicket
  2. WICKET-1736

Allow Access to AutoCompleteTextField AutoCompleteBehavior

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.4, 1.4-M2
    • Fix Version/s: 1.3.5, 1.4-RC1
    • Component/s: wicket
    • Labels:
      None
    • Environment:
      N/A

      Description

      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:

      	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);
      			}
      
      		});
      	}
      

      One solution to this is to extract the creation of the AutoCompleteBehavior to a method:

      	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);
      		}
      	}
      

        Activity

        Will Hoover made changes -
        Description 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}
        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}
        Igor Vaynberg made changes -
        Fix Version/s 1.4-M4 [ 12313295 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.3.5 [ 12313175 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Igor Vaynberg made changes -
        Assignee Igor Vaynberg [ ivaynberg ]
        Will Hoover made changes -
        Field Original Value New Value
        Description 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 = getAutoCompleteBehavior(renderer, settings);
        if (autoCompleteBehavior == null) {
        throw new NullPointerException("Auto complete behavior cannot be null");
        }
        add(autoCompleteBehavior);
        }

        protected AutoCompleteChoiceBehavior getAutoCompleteBehavior(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}
        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}
        Will Hoover created issue -

          People

          • Assignee:
            Igor Vaynberg
            Reporter:
            Will Hoover
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development