Generate a List of Select Input Label & Value Dynamically

Hello,
I have a select input that I wanted to generate & control with logic because I want to show 3 options in one case (user has certain plan) and 2 options in another case.

I didn’t want to rely on DB/Backend to generate the options and at the same time the manual list didn’t offer me a way to show/hide options. Therefore, I used the following code which I hope you can find helpful if you want to control your options based on logic and not have to duplicate the input select.

// Define the condition
let condition = true; // Replace with your actual condition

// Define the two different lists
let list1 = [
  { label: 'BuyTest Label here', value: 'BuyTest' },
  { label: 'Buy Label here', value: 'Buy' },
  { label: 'Sales Label here', value: 'Sales' },
];

let list2 = [
  { label: 'BuyTest Label here', value: 'BuyTest' },
  { label: 'Sales Label here', value: 'Sales' },
];

// Use the condition to determine which list to return
return condition ? list1 : list2;

Here is an updated version showing an example function that would determine the condition:

// Access the global variable
const planFeatures = pluginVariables['f5856798-485d-47be-b433-d43d771c64e1']['user']?._user_subscription?._plan_features;

// Search for the object where key="feature_key" and value="enable_exp_buy_intent"
const feature = planFeatures.find(feature => feature.feature_key === "enable_exp_buy_intent");

// Return true if value is 1, otherwise return false
const condition = feature ? feature.value === 1 : false;

// Define the two different lists
let list1 = [
  { label: 'Your Label', value: 'BuyTest' },
  { label: 'Your Label', value: 'Buy' },
  { label: 'Your Label', value: 'Sales' },
];
let list2 = [
  { label: 'BuyTest Label here', value: 'BuyTest' },
  { label: 'Sales Label here', value: 'Sales' },
];

// Use the condition to determine which list to return
// First is run if condition = true
return condition ? list1 : list2;