Skip to content
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

setText method missing #78

Open
tonila opened this issue Feb 25, 2021 · 4 comments
Open

setText method missing #78

tonila opened this issue Feb 25, 2021 · 4 comments

Comments

@tonila
Copy link

tonila commented Feb 25, 2021

There was no option to set text.

I extended EditableSelect with 'setText' method like this as a workaround. It would be nice, if method was added to editableSelect.

EditableSelect.prototype.setText = function (text) {
    this.$input.val(text);
    if (this.options.filter) this.hide();
    this.filter();
};
@wannadream
Copy link
Collaborator

What is the use case here? I believe you can call select($li) to achieve the same function.

@tonila
Copy link
Author

tonila commented Mar 3, 2021

Use case was, that I needed to set text, to value, that was not in the select list.

If I have following values in select:

<select id="editable">
  <option>Finland</option>
  <option>Sweden</option>
  <option>Norway</option>
</select>

And I need to set text to "Denmark":

$('#editable').editableSelect('setText', 'Denmark');

@wannadream
Copy link
Collaborator

wannadream commented Mar 8, 2021

Check this:

this.$input.val($li.text());

The select($li) does it already.

@tonila
Copy link
Author

tonila commented Mar 8, 2021

Ok. Am I missing something here?

I altered setText function I am proposing from select method you are referring to.

The reason for altering select method was, because it returns if list does not already contain the item.

if (!this.$list.has($li) || !$li.is('li.es-visible:not([disabled])')) return;

So there must be a way to setText in editable-select by using the select method. I just don't understand how it is done. So could you provide an example?

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

2 participants