"is owner logged in check, switch" (SOLVED)

@yisrael-wix
My page has a members area with members info stored in PrivateMembersData(read Only)
on top of that i got a paid plan where paying members can generate a dynamic page from a form input to Database2, this all works.

What i have been trying to do is hide/show a button on the generated dynamic page based on an email comparison via the below 2 steps:
Step 1: on form submit copy email from PrivateMembersData and insert it into Database2.
Step 2: compare current user email (wix-users) to Database2 email and hide/show via if/else:
if (the 2 emails are the same)
show button
else
hide button

I have tried several approaches but no success, is this possible at all?

i have tried checking 2 input fields against each other:

$w.onReady( function () {
let value1 = $w( “#input1” ).value;
let value2 = $w( “#input2” ).value;
if ( value1 === value2) {
$w( “#updatebutton” ).show(); //do this thing
}
else if ( value1 !== value2) {
$w( “#updatebutton” ).hide(); //or else do this other thing
}});

does’nt work…

If #input2 is connected to a dataset that is tied to Database2, you need a dataset onReady statement too.

$w.onReady(function () {
    $w("#dataset2").onReady( () => {
         let value1 = $w("#input1").value;
         let value2 = $w("#input2").value;
         if ( value1 === value2) {
            $w("#updatebutton").show();  //do this thing
         } else {
            $w("#updatebutton").hide();  //or else do this 
         }
    });
});

@ anthonyb

Great job buddy :smiley:
Yes! that worked your the man, hats off!!

now all i need is to collect email from database 1 and insert it into database 2

ah i solved it!

Dual database setup:
In database 1 (the DB that holds login info) the field “loginEmail” is the primary field
in database 2 (the DB that holds profile info) set OwnerEmail to primary field as well
(not sure if this is required)

PAGE 1:
Register page:
page has:
1 button for login/logout
and
1 button that is hidden/shown to nav to profile update/creation
the code on the page:
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;

$w.onReady( () => {
if (wixUsers.currentUser.loggedIn) {
$w( “#loginButton” ).label = “Logout” ;
$w( “#profileUpdateButton” ).show();
}
else {
$w( “#loginButton” ).label = “Login” ;
$w( “#profileUpdateButton” ).hide();
}
} );

export function loginButton_click(event) {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w( “#loginButton” ).label = “Login” ;
$w( “#profileUpdateButton” ).hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;

// prompt the user to log in
wixUsers.promptLogin( { “mode” : “login” } )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query( “NameOfYourDatabase” )
.eq( “_id” , userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0 ) {
// create an item
const toInsert = {
“_id” : userId,
“FieldNameOfYourEmailinDatabase2 aka ownerEmail” : userEmail
};
// add the item to the collection
wixData.insert( " NameOfYourDatabase " , toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w( “#loginButton” ).label = “Logout” ;
$w( “#profileUpdateButton” ).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}
export function profileButton_click(event) {
[wixLocation.to(](wixLocation.to(‘/Someadres) [’/SomeAdres](wixLocation.to(‘/Someadres) YouWrote /${ ownerEmail }’ );
}


PAGE 2:
make a dynamic page that uses the ownerEmail (ProfileUpdater/${ownerEmail}) for adress
this page has:
dataset 1 (read only) which hold member log in data
and
dataset 2 (read & write) which is where the profile will be created
text input: inputYourLoginEmail
and
text input: inputPageOwnerEmail
and
lots of user input fields for profile creation/update connected to database 2
and
1 submit button
and
is owner logged in check

the code on the page:
On page where button is hidden or shown:
$w.onReady( function () {
//prepare datasets
$w( " #dataset1 " ).onReady( () => {
$w( " #dataset2 " ).onReady( () => {
//get the values from the inputs
let value1 = $w( " #inputYourLoginEmail " ).value;
let value2 = $w( " #inputPageOwnerEmail " ).value;
//check the values against each other
if ( value1 === value2) {
//hide or show stuff
$w( " #submitButton " ).show(); //shows the submit button on this page
} else {
$w( " #submitButton " ).hide(); //hides the submit button on this page
}
}); }); });


PAGE 3:
This page is a dynamic profile page with member access
and the same “is owner is logged in check” as above.
This shows info and buttons depending on if owner is logged in:

inputs and datasets:
dataset 1 (read only) which hold member log in data
and
dataset 2 (read only)
text input: inputYourLoginEmail
and
text input: inputPageOwnerEmail
and
lots of user input fields for profile creation/update connected to database 2
and
1 submit button

the code on the page:
On page where stuff is hidden or shown:
$w.onReady( function () {
//prepare datasets
$w( " #dataset1 " ).onReady( () => {
$w( " #dataset2 " ).onReady( () => {
//get the values from the inputs
let value1 = $w( " #inputYourLoginEmail " ).value;
let value2 = $w( " #inputPageOwnerEmail " ).value;
//check the values against each other
if ( value1 === value2) {
//hide or show stuff
$w( " #someButtonOrTextOrImage " ).show(); //shows stuff
} else {
$w( " # someButtonOrTextOrImage " ).hide(); //hides stuff
}
}); }); });


There is probably an easier way to do this without using inputs and instead comparing databases directly, but im not a coder so use this at your own risk.

Oh and remember to set the check inputs to “hidden on load”.

hey guys, I have a similar but much easier problem. I have created a member page where members can create a database item to provide there data. That for I have made a button to give the member the chance to create a new database item. That all work fine so fare.

Unfortunately the “Create new Item Button” stays active and that means members can create unlimited items. This is not wanted. I only want one member to create one item.

My idea now is to compare Loged-In Member ID with owner. If same I want to disable the button. I hope that you get what I want to do.

Because of the filter settings I already have connect the created Items with creators.

This is my poor try. Maybe someone can help:

$w . onReady ( function () {
//prepare datasets
$w ( “#dataset1” ). onReady ( () => {
$w ( “#dataset2” ). onReady ( () => {
//get the values from the inputs
let value1 = $w ( “_owner” ). value ;
let value2 = $w ( “_id” ). value ;
//check the values against each other
if ( value1 === value2 ) {
//hide or show stuff
$w ( “#button2” ). disable (); //shows the submit button on this page
}
}); }); });