[SOLVED] Disable inputs for Demo and Enable inputs for members/clients

Hi, I hope you can help me.
I’m trying to write a code that allows to disable an input field (switch, dropdown, text or button) if the user is NOT a member/client (using the member ID) and at the same time enable the same input field if the user is already a client (identified by the ID).
The user has 3 options:
a) If “dropdown1” equals “Demo” then enable “switchDemo” and disable “switchBasic” and disable “switchPro”.
b) If “dropdown1” is equal to “Basic” then enable “switchDemo” and “switchBasic” and disable “switchPro”
c) If “dropdown1” is equal to “Pro” then enable the 3 switch / Demo / Basic and / Pro.

I have tried with the following code (for the Demo) without success:

$w.onReady (function () {
if ($w(‘#dropdown1’).value === “Demo”) {
$w(‘#switchDemo’).enable();
$w(‘#switchBasic’).disable();
$w(‘#switchPro’).disable();

 } else { 
     $w('#switchDemo').disable(); 
     $w('#switchBasic').disable(); 
     $w('#switchPro').disable(); 
 } 

});

The problem with this code is that switch input fields remain disabled and do not change with the user’s selection.

Hope you can help me. Thanks you all!!

I also try this code but still not working:

$w.onReady( function () {
let thePlan = $w(‘#dropdown1’).value;

if (thePlan === ‘Demo’) {
$w(‘#switchDemo’).enable();
$w(‘#switchBasic’).disable();
$w(‘#switchPro’).disable();
}

if (thePlan === ‘Basic’) {
$w(‘#switchDemo’).enable();
$w(‘#switchBasic’).enable();
$w(‘#switchPro’).disable);

}

if (thePlan === ‘Pro’) {
$w(‘#switchDemo’).enable();
$w(‘#switchBasic’).enable();
$w(‘#switchPro’).enable();

}
});

$w.onReady( function () {

if (wixUsers.currentUser.loggedIn) {

//enter code here for logged in member

}  **else** 

//enter code here for user that is not logged in / not a member

})

Thank you! I need to identify them by user ID, since each input field corresponds to a different plan: Demo, Basic or Pro.
With this solution you say I only identify if it is logged or not, but I do not identify what kind of client it is (Demo, Basic or Pro)

@guevarapp

import wixUsers from ‘wix-users’;

$w.onReady( function () {

if (wixUsers.currentUser.loggedIn) {

let userID = wixUsers.currentUser.id; //this will give you the user ID of the current user logged in
console.log (userID);

//enter code here for logged in members userID

} else

//enter code here for user that is not logged in / not a member

})

@mikemoynihan99
It still does not work. Even if the user is login and select the options DEMO, BASIC or PRO. Switch input fields do not change, they remain disabled.

Looking at your picture so you don’t actually have a dropdown, what you have is a radiogroup and sliders. You want to enable the sliders based on the selected radiogroup. You need to add a button to your page and create an onClick event that will read the selected radiogroup at that moment in time and then activate the relevant slider. Something like below:

$w.onReady( function () {

  $w("#slider1").disable(); //this is your demo slider 
  $w("#slider2").disable(); //this is your basic slider 
  $w("#slider3").disable(); //this is your pro slider 

}
);

export function Button1_click(event) {

//this is code executed if the demo option is selected from the radiogroup

if ((($w(“#radioGroup1”).value) === “Radio button1”)) {
$w(“#slider1”).enable();
$w(“#slider2”).disable();
$w(“#slider3”).disable();
}

//this is code executed if the basic option is selected from the radiogroup

if ((($w(“#radioGroup1”).value) === “Radio button2”)) {
$w(“#slider2”).enable();
$w(“#slider1”).disable();
$w(“#slider3”).disable();
}

//this is code executed if the pro option is selected from the radiogroup

if ((($w(“#radioGroup1”).value) === “Radio button3”)) {
$w(“#slider3”).enable();
$w(“#slider2”).disable();
$w(“#slider1”).disable();
}

console.log(($w(“#radioGroup1”).value)) ;

}

[SOLUTION]

import wixData from ‘wix-data’;

$w.onReady( function () {
$w(‘#dataset1’).onReady( () => {
$w(‘#switchDemo’).disable();
$w(‘#switchBasic’).disable();
$w(‘#switchPro’).disable();

let isEmpty = $w(‘#dataset1’).getCurrentItem();
let thePlan = $w(‘#inputPlan’).value;

if ( thePlan === ‘Demo’ ) {
$w(‘#switchDemo’).enable();
$w(‘#switchBasic’).disable();
$w(‘#switchPro’).disable();
$w(‘#text47’).text = Demo New User!;

}  **if**  ( thePlan === 'Basic') { 
  $w('#switchDemo').enable(); 
  $w('#switchBasic').enable(); 
  $w('#switchPro').disable(); 
  $w('#text47').text = `Basic New User!`; 
} 

if ( thePlan === ‘Pro’) {
$w(‘#switchDemo’).enable();
$w(‘#switchBasic’).enable();
$w(‘#switchPro’).enable();
$w(‘#text47’).text = Pro New User!;

} 

console.log(($w(‘#inputPlan’).value)) ;
} );

});