Open Rui90 opened 5 years ago
heeeeelp
I need somebody heeeelp
Just encountered the same issue and came here looking for a more elegant solution.
A hacky solution I'm using at the moment is to include the necessary text for the search to work within the label, and then hide it using css. Forexample:
<style>
.hidden{
display: none;
}
</style>
...
list: [
{ label: "brasil<span class="hidden"> br</span>", value: "br"},
{ label: "portugal<span class="hidden"> pt</span>", value: "pt"},
{ label: "france<span class="hidden"> fr</span>", value: "fr"},
]
If anyone has a cleaner solution, I'm all ears!
EDIT: To clean the label text and prevent it from inserting the span into your input as plaintext, you can use the replace function as follows:
let awesomplete = new Awesomplete(elem, {
minChars: 0,
autoFirst: false,
list: [],
replace: function (text) {
let result = extractNameFromResult(text);
this.input.value = result;
}
});
function extractNameFromResult(text) {
const index = text.indexOf('<span class="hidden">');
const result = text.substr(0, index);
return result;
}
I've basically made a "serialize" "deserialize" so my list only has labels, and when I'm about to save I just parse to the key.... Not good, but, works
I have the following autocomplete which uses the awesomplete plugin. The thing is this is an autocomplete, where the value selected is different from the label that should be showned.
Awesomplete component:
And this are the options that I'm passing to the component:
So when I click the Input I have a list of Brasil, Portugal, France and when I choose one, for instance, France, what I see on the input is fr. I want the control to have the fr value, but I want the input to display France.