question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Capability to differentiate value from displayed text

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vlazarcommented, Mar 12, 2016

Separate label/value is landed #16866 It is also possible to initialize list with separate label/value via <datalist> or <ul>.

Read about different label and value at the end of Basic usage section and about new data method at the end of Extend section.

0reactions
vlazarcommented, Feb 15, 2016

To everyone interested in differentiating value from displayed text, aka key/value feature, aka array of objects feature.

The code is ready and it’s almost 100% backward compatible. To ensure everything working fine for you we need your help with testing it in the wild before it’s released. See this PR: Separate label/value for each suggestion in list

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spot the difference: Numbers stored as text | Blog | Analyse-it®
When you type a value into a cell, Excel looks at what you've typed and decides whether it's a valid number. If it...
Read more >
Understanding Success Criterion 1.4.11: Non-text Contrast | WAI
The principle is that contrast ratio (the difference in brightness) can be used to distinguish text or graphics. For example, G183: Using a...
Read more >
How to Create a Unique Value Proposition: 7 Best Examples
Your value proposition determines if people read more about your product or hit the back button. Here's how to get it right, with...
Read more >
Difference between html() text() and val() methods in jQuery
In this article, we are going to discuss the differences between html(), text(), and val() methods and their usage.
Read more >
Features and Capabilities - Scaled Agile Framework
Feature estimation supports forecasting value delivery, applying WSJF prioritization, and sizing epics by splitting them into features and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found