Skip to content

clearElement & clearTarget doesn't update selected option #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mikeblum opened this issue Oct 20, 2014 · 1 comment
Open

clearElement & clearTarget doesn't update selected option #158

mikeblum opened this issue Oct 20, 2014 · 1 comment

Comments

@mikeblum
Copy link

In the source code, these two functions:

  , clearElement: function () {
    this.$element.val('').focus();
  }

  , clearTarget: function () {
    this.$source.val('');
    this.$target.val('');
    this.$container.removeClass('combobox-selected');
    this.selected = false;
  }

Don't actually clear the selected value from the combobox. I know that we could just do a $el.val('') but I wanted to make this fix a part of core.

I wanted to accomplish two things:

  1. Don't focus on the control when clearing programmatically
  2. clear all attributes (target, source, and element)

The fix is quite minor, here's my solution:

        , clear: function(){
            this.$element.val('');
            this.$source.val('');
            this.$target.val('');
            this.$container.removeClass('combobox-selected');
            this.selected = false;
        }

Its very similar to clearTarget but also cleans up the ui in the same call. I don't want to break existing configurations so i opted to make a new clear function.

Should clearTarget just be updated to include this line?

 this.$element.val('');

Also, could we remove the .focus from clearElement?

  , clearElement: function () {
    this.$element.val('').focus();
  }

It makes it awkward for us to clear the box but then get focus forced to the combobox and away from whatever it was pointed at previously, just my opinion.

@mikeblum
Copy link
Author

I got some strange UX behaviour so i revised my clear function to doi a clear value and refresh:

            this.$element.val('');
            this.source = this.parse();
            this.options.items = this.source.length;

and this seems to work nicely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant