Skip to content

Capability to differentiate value from displayed text #593

Description

@ThomasG77

Your library is cool but maybe due to the habit of <select><option> couple for sending identifier, I would like to use a value that differs from the text when event 'awesomplete-selectcomplete' is fired.
Another reason could be the fact, that I want to avoid encoding issue. With accents (I'm French), I don't want to bother about encoding client/server when sending info (although nowadays, everyone use UTF-8, in my dreams...) so an identifier is better IMO.

I don't know if it's a design choice but I didn't see any ways to achieve it.
To try to bypass the lib behaviour cleanly, I created the following example below

<input id="myinput" list="mylist" />
<datalist id="mylist">
    <option value="a">Ada</option>
    <option value="b">Java</option>
    <option value="c">JavaScript</option>
    <option value="d">Brainfuck</option>
    <option value="e">LOLCODE</option>
    <option value="f">Node.js</option>
    <option value="g">Ruby on Rails</option>
</datalist>

<script>
document.querySelector('#myinput').addEventListener('awesomplete-selectcomplete', function(evt){
  console.log(this.value);
})
</script>

Unfortunately, it echoed Python but never a when choosing the first option.

I could always do the below really dirty solution but I would prefer to avoid it.

What is the way to go for my requirements if any?
Thanks for your input.

document.querySelector('#myinput').addEventListener('awesomplete-selectcomplete', function(evt) {
  var lib = this.value;
  var val = Array.prototype.slice.call(document.querySelectorAll('#mylist option')).filter(function(option) {
    if (option.text == lib) {
      return true;
    };
    return false;
  })[0].value;
  console.log(lib, val);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions