I’m trying to create a search functionality where the user can both enter and click a button to submit. The url is created based on keyword in user input field. I need to programmatically click a button, see below in red. In plain javascript I would use click() but it looks like I can’t do that in Corvid. Anyone solved this differently?
function search() {
let keyword = $w(“#Searchinput”).value;
console.log(keyword);
let searchUrl = (" https:// url ?q= " + keyword);
$w(“#Searchbutton”).link = (searchUrl);
}
export function Searchinput_keyPress(event) {
if (event.key===“Enter”) {
search();
$w(“#Searchbutton”).click(); <---- CAN I DO SOMETHING LIKE THIS?
}
}
If you want to do a user input search through Wix that you would like to be enterable by both submit button click and keypress click, then you need to do the two event handler functions for them.
The click event handler will be for the submit button itself.
export function searchButton_onClick(event) {
The above is how it is added when you add the onClick event handler function through the search button properties panel, with the code getting added automatically to the end of your current page code, so delete if you have already added it otherwise it will be duplicated click function.
$w("#searchButton").onClick( (event) => {
The above is how to add the code to your page with the onClick event handler written into the code itself and therefore not needing it to be added through the properties panel for the button itself.
Whilst the keyPress event handler will be on the user input text box instead.
export function userInput_onKeyPress(event) {
if (event.key === "Enter") {
The above is how it is added when you add the onkeyPress event handler function through the user input properties panel, with the code getting added automatically to the end of your current page code, so delete if you have already added it otherwise it will be duplicated keyPress function.
$w("#userInput").onKeyPress( (event) => {
The above is how to add the code to your page with the onkeyPress event handler written into the code itself and therefore not needing it to be added through the properties panel for the user input text box itself.
Have a look in the Documentation tab in the forum header and see the examples page and video tutorials where you can get more help and info and be able to open the examples in your own editor which will have the example all set up with all code already added to the page etc.
You might also benefit from reading about using Wix Corvid here, so that you know how to implement the JS correctly into your website.
For like if you want to do a Wix Data Query on a dataset for example.