-
Notifications
You must be signed in to change notification settings - Fork 610
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
Feature/handle array of objects #16795
Feature/handle array of objects #16795
Conversation
Pass the selected item's dataset to the `awesomplete-select` and `awesomplete-selectcomplete` events to allow firing actions based on secondary keys in the object
Merge branch 'gh-pages' into feature/handle-array-of-objects
- Fix bug created in LeaVerou#16794, which caused different behaviours when selecting an item with the keyboard and with a mouse.
Not sure why the tests are failing - when I test in the browser locally, it all seem to work just fine... |
@vlazar - Sorry to bug you, but could you maybe take a look and see why the tests are failing? I tried, but didn't really manage to figure it out. Thanks! |
@TxHawks I saw the call signature was changed from With changes you've made... Does the |
I probably was not clear enough. What I was referring to is this line https://github.com/TxHawks/awesomplete/blob/feature/handle-array-of-objects/awesomplete.js#L205 The However I think this second argument is already quite a controversial feature to have. Why someone might need to pass originalEvent to the public API method in the first place? Maybe #16794 was a nice addition, but should it really change the public API? We might want to hear @LeaVerou opinion on this matter. |
@vlazar - You are absolutely right. I changed the code to that the event is optional again. |
No need to modify the event object, the selected element just needs to be passed to the fired events in `select()`.
|
||
arrOfObj.addEventListener('awesomplete-selectcomplete', function(e){ | ||
// Do something with e.originalTarget.getAttribute('data-*') | ||
console.log(e.originalTarget.getAttribute('data-url')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be a good idea to do something visual here, instead of doing console.log
. One obvious example would be to use only URL property of item as input value when selected.
Unfortunately, having selected element passed into awesomplete-selectcomplete
here in e.originalTarget
allows only a hacky way to use different value for input when selected.
We can change input value:
e.target.value = e.originalTarget.getAttribute('data-url');
But this will happen after an input value was already changed to selected.textContent
by awesomplete itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think that changing the input value in the event isn't good practice, as it can be easily done in the item
function to begin with.
I do agree that console.log()
doesn't exactly showcase this ability very well though. I'll try and think of something better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strike what I said in the previous comment, it's absolutly rubbish.
Note to self: do not write when sleep deprived.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understood you actually meant replace
function, where the input value is assigned from selected text now. Having item
instead of text
in replace
would make it possible to assign either item's key or value or some combination of them to input.value
.
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 |
Will do. Was following the thread(s) on #16852 and it looks pretty solid |
You wen back and forth on |
Gotcha! We only care about external API, not internal implementation. But it's a good idea, I'll add a known issue with having Suggestion instead of just text as before. |
Separate Read about different |
Just a thought: I think we still need an advanced example based on yours. Like a small bookmark manager maybe? |
Closing this one since array of objects case is already supported. |
Addresses #16788 by attaching the selected item's dataset to the event object that is passed when the
awesomplete-select
andawesomplete-selectcomplete
events are fired.In cases where out
list
is an array of objects, this allows addingdata-*
attributes to theli
s when building the items based on keys in the object, and then accessing them when theawesomplete-select
andawesomplete-selectcomplete
events are fired.