Looking at value within widget.datasource

Hi, I need to look at the widget.datasource and check if the text is "Swimming" then based off whether it is or not will hide certain fields etc,

However i can't seem to get the code to work for this. Please can you help. Below is the code i am attempting right now

/** Programme Choices **/
function populateProgrammeChoices() {
if (fd.field("Service").value === "Hampshire") {
// fd.field("ExerciseProgramme").widget.dataSource.data(["Swimming", "Online Gym Programme", "Netball"]);
fd.field("ExerciseProgramme").widget.dataSource.data(["Netball"]);
} else if (fd.field("Service").value === "Isle of Wight") {
fd.field("ExerciseProgramme").widget.dataSource.data(["Netball"]);
}
if (fd.field("Service").value === "Hampshire") {
fd.field("ExerciseProgramme").value === "Swimming";
}

if (fd.field("Service").value === "Hampshire") {
if (fd.field("ExerciseProgramme").value === "Swimming") {
// When Service is "Hampshire" and Programme is "Swimming"
fd.control("SwimmingFull").hidden = false;
} else {
// For all other cases in Hampshire
fd.control("SwimmingFull").hidden = true;
}
} else if (fd.field("Service").value === "Isle of Wight") {
if (fd.field("ExerciseProgramme").value === "Swimming") {
// When Service is "Isle of Wight" and Programme is "Swimming"
fd.control("SwimmingFull").hidden = false;
} else {
// For all other cases in Isle of Wight
fd.control("SwimmingFull").hidden = true;
}
} else {
// For all other cases where Service is neither "Hampshire" nor "Isle of Wight"
fd.control("SwimmingFull").hidden = true;
}
}

Hello @Ibrahim,

What forms are you using? Public or SharePoint forms?

What is the type of the ExerciseProgramme field? Please share the screenshot from the designer.

Are you getting any errors in the browser console?

Hi @Margo

This is a public form.
It is a dropdown field. Although there are no values in the actual field it's populated using the widget.datasource

And no errors in console

@Ibrahim,

If you need to check whether there is an option in the drop-down list, use this condition:

let dropdown = fd.field('ExerciseProgramme');
if(dropdown.widget.dataSource.data().indexOf('Swimming') > -1) {
//do something
}