I have a database with specific codes for specific people. I want a button to appear only if someone types their code in correctly. Coding is not really my strength, and for whatever reason I can’t even get the button to collapse or be hidden with $w(“#button2”).collapse or $w(“#button2”).hide to begin with. I’ve been trying different like “if $w(”#input1").value.eq" but obviously that doesn’t work because you can’t put .eq on a string. Seems like such a basic thing but I need help.
I also had the problem although I have been dealing with Velo for months. This can happen. You forgot the brackets at the end of your method ().
So it should be correctly
$w("#button2").hide().
For example, if you want to hide an element by default and only make it visible by pressing a button, the code would be:
$w("#element").hide(); //element is hidden by default
$w("#button").onClick(() => { //button makes element visible
$w("#element").show();
});
Your other problem I honestly didn’t quite understand, maybe you can give more info on that.
I am relatively new to learning programming, but try to do roughly what you want:
I have a text input field and want that if the text you type matches what I set before (in example it is the word “test”), then the button should appear. Otherwise the button should be hidden.
For this I have created an input field named “input1” and next to it a button “button1”.
First I have to create an onInput event, this is done on the lower right side in the code window (see picture).
Now a pre-made code appears to me. I only need this part of it (Do not forget to write in front that the button should be hidden by default):
$w("#button1").hide();
export function input1_input(event) {
}
Now I write an if-condition inside the onInput function (If the value of the input matches this text, then the button should become visible, otherwise hide() again):
if ($w("#input1").value === "test") {
$w("#button1").show();
} else {
$w("#button1").hide();
}
The entire code:
$w("#button1").hide();
export function input1_input(event) {
if ($w("#input1").value === "test") {
$w("#button1").show();
} else {
$w("#button1").hide();
}
}
Your source instead of the text is up to you.
I hope it helped you a little, good luck!
Ok so the () worked, facepalm. But the problem is that each different person in my dataset has an individual code for themselves. So unless I go through and add each individual code into velo, which would be painstaking to keep up with, it would really help if I was able to make it so that when someone types in their code, it filters to them and they’re able to go to their individual “item” page. Right now I have this code to filter:
let SearchValue = $w(“#input1”).value;
$w(“#dataset1”).setFilter(wixData.filter().eq(“code”, SearchValue))
But I have no idea how to get from there to button takes them to their page. I currently have it set so that the button is connected to the items page for the dataset. But right now I have it set up so that the button shows up if there’s any input, but if I type in someone’s code correctly and try to click on the button it takes me nowhere. Like does nothing. So that’s confusing. I tried seeing if I could trigger a query when someone starts typing, and if it returns the right result to show the button … but I can’t tell if I was just doing it wrong or if it doesn’t really help if you’re already filtering the dataset. It probably needs to be like filtered first before it can take you to a page … I don’t know.
Honestly, I’m afraid I don’t have enough knowledge to help you accurately. I also work with filters and databases but use a different method than you. I don’t want to tell you anything wrong and I hope someone else can help you.
Ps.:
it’s a bit unprofessional, but try asking ChatGPT. He often gave me at least correct approaches and I found a solution. Just make sure that you say that it is a Wix Velo code and Wix database/dataset. If you use those keywords he gives more precise answers.
I solved this problem by calling for a query that was filtered based on user input.
export function input1_input(event) {
let SearchValue = $w(“#input1”).value;
wixData.query(“Items”)
.eq(“code”, SearchValue)
.find()
.then((results) => {
if(results.items.length > 0) {
console.log(results.items[0]);
$w("#button2").show();
} else {
$w("#button2").hide()
}
})
.catch((err) => {
console.log(err);
});