Hello. I have a search bar to search my dataset. I am using the on key press event to trigger the search. The problem is, the search bar searches the dataset before the person presses enter. Is it possible to let the search bar wait till the person presses enter?
Also, Can I have a search button as well (using the onClick event).
~Thanks~
Arthur
import wixData from 'wix-data';
$w.onReady( function() {
})
export function input1_keyPress(event) {
let searchValue = $w("#input1").value;
let filter = wixData.filter()
.contains('name', searchValue)
.eq('stat', 'Published')
.or(wixData.filter().contains('title',searchValue)
.eq('stat','Published')
)
$w("#dataset1").setFilter(filter);
}
Hi!
If you wanted the search to be triggered only after pressing enter you’d need to check IF the enter key has been pressed and then run the rest of your code within the condition. Without the event value the keyPress event would be triggered by any key.
You also want to make sure your input function is invoked within the onReady function so that it runs after the items on the page have loaded.
Check out the code below for reference:
$w.onReady(function () {
input1_keyPress();
})
export function input1_keyPress(event) {
// Checks if the enter key has been pressed
if(event.key === "Enter"){
console.log("Enter has been pressed")
// Your search code should go here
}
}
Feel free to check out the onKeyPress API.
I hope this helps you out!
Best regards,
Miguel
Thank you so much, it worked! I have some more questions. I will make a new post for them? I think that way it would be more tidier. If you can spare some more time, please help me!
~Thank you so much!~
Arthur 