Hi so below is a link to my current project:
Here is my code that makes up my current project. Everything works just need the label to change to what matches with is selected from drop down. Please anyone know how to do this? Here is my code:
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#countyList").options = [
{"label": "Utah County", "value": "/utah-county"},
{"label": "Second County", "value": "/second-county"},
{"label": "Third County", "value": "/Third-County"},
];
if ($w('#countyList').options === "label" && "Utah County") {
$w('#button5').label === "Utah County";
} else if ($w('#countyList').options === "Second County") {
$w('#button5').label === "Second County";
} else if ($w('#countyList').options === "label" && "Third County") {
$w('#button5').label === "Third County";
} else {
$w('#button5').disable();
}
})
$w.onReady(function () {
$w('#button5').disable();
$w('#button5').label = "Select a County";
})
export function button5_click(event) {
let goToUrl = $w('#countyList').value;
wixLocation.to(goToUrl);
}
export function countyList_change(event) {
$w('#button5').enable();
}
ADD ON!
One thing. I am trying to add on to this. So basically I want “Select Your County To Get Started” to show in the list of dropdown at the top. So basically if you select that it will disable the button with label saying “Select County” and when selecting county it will enable like how it does already. So basically just adding “Select Your County To Get Started” option which I have already. But it enables the button when click on that option I want it so if you select that option will disable it and select county it will enable then if reselect that first option it will disable button. Here is screen shot below and current code. If need clear information let me know if this is not clear enough.
Step 1: When you first open the drop down option list
Step 2: After opening the drop down list and selecting that option “Select Your County To Get Started”
Step 3: After selecting a county from the list in this case I selected “Box Elder County” and then I went back and selecting the first option “Select Your County To Get Started” and it still kept that label and did not disable the button with changing label back to “Select a County”
click here for example of the current problem I am having.
Here is my code:
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(function () {
$w('#countyList').placeholder = "Select Your County To Get Started";
$w('#button5').disable();
$w('#button5').label = "Select a County";
$w("#countyList").options = [
{"label": "Select Your County To Get Started"},
{"label": "Beaver County", "value": "/beaver-county"},
{"label": "Box Elder County", "value": "/box-elder-county"},
{"label": "Cache County", "value": "/cache-county"},
{"label": "Carbon County", "value": "/carbon-county"},
{"label": "Daggett County", "value": "/daggett-county"},
{"label": "Davis County", "value": "/davis-county"},
{"label": "Duchesne County", "value": "/duchesne-county"},
{"label": "Emery County", "value": "/emery-county"},
{"label": "garfield County", "value": "/garfield-county"},
{"label": "Grand County", "value": "/grand-county"},
{"label": "Iron County", "value": "/iron-county"},
{"label": "Juab County", "value": "/juab-county"},
{"label": "Kane County", "value": "/kane-county"},
{"label": "Millard County", "value": "/millard-county"},
{"label": "Morgan County", "value": "/morgan-county"},
{"label": "Piute County", "value": "/piute-county"},
{"label": "Rich County", "value": "/rich-county"},
{"label": "Salt Lake County", "value": "/salt-lake-county"},
{"label": "San Juan County", "value": "/san-juan-county"},
{"label": "Sanpete County", "value": "/sanpete-county"},
{"label": "Sevier County", "value": "/sevier-county"},
{"label": "Summit County", "value": "/summit-county"},
{"label": "Tooele County", "value": "/tooele-county"},
{"label": "Uintah County", "value": "/uintah-county"},
{"label": "Utah County", "value": "/utah-county"},
{"label": "Wasatch County", "value": "/wasatch-county"},
{"label": "Washington County", "value": "/washington-county"},
{"label": "Wayne County", "value": "/wayne-county"},
{"label": "Weber County", "value": "/weber-county"}
];
})
export function countyList_change(event) {
$w('#button5').enable();
let options = $w('#countyList').options; // this is the code to make sure options is defined. <<<
let idx = $w('#countyList').selectedIndex
$w('#button5').label = options[idx].label;
}
export function button5_click(event) {
let goToUrl = $w('#countyList').value;
wixLocation.to(goToUrl);
}
If you can help me figure this out so basically to shorten it down. The main issue is:
Step 1: click drop down and if select option and reselect the first option again it disables with label “Select County”
Step 2: And once you select another option it enables. Everything is working just the first option should not be a choice it should keep button disabled.