Code not working in lightbox

Hi,

I have an email input field (and button) in a lightbox that loads when a page loads. I want the user to enter their email address which then checks against a dataset and if the email address exists then they can view the page, so I need to close the lightbox.

I am using the following code (which works fine on a normal page) but doesn’t seem to function in a lightbox…

import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';

export function btnLogin_click(event, $w) {

    wixData.query("MembersOnly")
        .eq('email', $w('#inputEmailAddress').value)
        .eq('approved', true)
        .find()
        .then((results) => {
 let items = results

 if (results) {
                console.log("Email match");
                wixWindow.lightbox.close();
            } else {
                console.log("Email address does not exist");
                $w('#textErrorMsg').show()
            }

        })
        .catch((err) => {
 let errorMsg = err;
            console.log(errorMsg);
        });

}

Can anyone help with where I’m going wrong?

Thanks,
Rachel

What isn’t working? What happens when you try it? Do you get any messages in the Developers console?

It’s just not doing anything and I don’t get any messages in the developer console.
Using the same code on a standard page but replacing

wixWindow.lightbox.close();

with

wixLocation.to("/isw");

my code is working fine and the correct messages are displayed in the developer console.

Still need more details. Please post the URL of your site. Only authorized Wix personnel can get access to your site in the editor.

Hi Yisrael,

The url of my site is www.markhatterassociates.co.uk

I have updated the code for the login and it is working fine in the ‘Login’ page under ‘Members’ where the page loads if a user tries to access the ‘ISW’ page without an active session. However, when I try to load the lighbox ‘Login’ this a) doesn’t open and b) the code is not doing anything.

The following code is in the ‘ISW’ page where wixLocation.to triggers the correct action but wixWindow.openLightbox does not.

$w.onReady(function () {

 let value = session.getItem("activeSession"); // "value"

 if (value) {
        console.log("Session Active - ", value);
    } else {
        console.log("Session not Active");
      //wixLocation.to("/member-login");
        wixWindow.openLightbox("Login");
    }

});

Many thanks,
Rachel

The Lightbox opens up just fine…


What happens for you? Did you get any messages in the Developers console?

Hi, thanks for taking a look for me.

The lightbox now opens fine but nothing is happening when I enter an email into the input field (one that I know exists in the dataset) There are no messages in the developer console.

My code now looks like this…

import wixData from 'wix-data';
import wixLocation from 'wix-location';
import { session } from 'wix-storage';

export function btnLogin_click(event, $w) {

 let searchValue = $w('#inputEmailAddress').value;

    wixData.query("MembersOnly")
        .eq('email', searchValue)
        .eq('approved', true)
        .find()
        .then((results) => {

 let members = results.items;

 if (results.length > 0) {

 let member = members[0];
 let emailAddress = member.email;
 let sessionId = member._id

                console.log(emailAddress, sessionId);
                session.setItem("activeSession", sessionId);
                wixLocation.to("/isw");

            } else {
                console.log("Email address does not exist");
                $w('#textErrorMsg').show()
            }

        })
            .catch((err) => {
            let errorMsg = err;
            console.log(errorMsg);
        });

}

When I run the same code in a normal page I get the correct messages in the developer console


or


All I see in the developer console when I enter an email address in the lightbox is…


?? Thanks

The code in your Lightbox has some problems:

You have:
wixData.query(searchValue)
It should be:
wixData.query(“MembersOnly”)

Also, you didn’t connect the button’s onClick() event handler. You need:

Hi Yisrael! Can’t believe I missed something so simple! My wixData.query was correct (see code posted above) but now I’ve added the button onClick() event handler all is working as expected!

Thank you for taking the time to help me :slight_smile: