I made a lightbox and added two text inputs and a submit button(#button2). I wrote this code but it not loading. The button function is not working.
Please help me
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
export function button2_click(event, $w) {
let emailid = $w('#input1').value;
let passkey = $w('#input2').value;
wixData.query("MemberList")
.eq('emailId', emailid)
.eq('password', passkey)
.find()
.then((results) => {
if (results.items.length > 0) {
wixLocation.to(`/quizmain/${results.items[0]._id}`);
}
if (results.items.length === 0) {
$w('#text13').show();
}
})
.catch((err) => {
console.log("err", err);
});
}
Sometimes trailing spaces in the data can be the problem. Try using "contain" rather than "eq" in the query. In other words, instead of the email being written to the collection as "johndoe@gmail.com", it could be "johndoe@gmail.com ". A query utilizing "eq" will not find this email, whereas one using "contain" would because it's looking for the existence of that email in the entire field. It doesn't have to exactly equal it.
.contains('emailId', emailid) .contains('password', passkey)
I have changed the property of the text to hidden on load.. Okay now its fine
But there is one thing, I am still facing...
I wrote this so that text pops up if the input values are not matching... But it is always displaying. How to hide that.
if (results.items.length === 0) { $w('#text13').show();
Thank you so much. Its now working.
Okay so, this is what the console is showing on clicking the button.
Loading the code for the site. To debug this code, open masterPage.js in Developer Tools. Loading the code for the Login popup. To debug this code, open tvdti.js in Developer Tools. {...} items: Array(0) length: 0 totalCount: 0 query: {...} invalidArguments: [...] filterTree: {...} provider: {...} collectionName: "MemberList" limitNumber: 50 included: Array(0)
Mayukh, sounds like you are receiving no results from the query; it doesn't even get to the .then area, in other words. If you are sure that the email and passkey entered should find a matching record in the collection, then it's probably a case of not having the right case on the fields or the collection. They are both case-sensitive. Also, be sure that you are using the field key. In the screen shot of the manage field dialog from the collection area for this particular field, the field key is "roomType."