In an salesforce lwc project i have a list of checkboxes populated with an array. The requirement is that when any other checkbox is selected it unselects the first one. I am trying this code
@track acc_array = [];
get options() {
return [
{ label: "Any option", value: "Any option" },
{ label: "Option One", value: "Option One" },
{ label: "Option Two", value: "Option Two" },
{ label: "Option Three", value: "Option Three" }
];
}
handleValidity(e) {
try {
var arr = e.target.value.join(";");
const tt = arr.split(";");
if (tt[0] == "Any Option" && tt.length > 1) {
tt.splice(0);
this.acc_array = tt;
}
this.message = "Selected " + this.acc_array;
} catch (e) {
this.message = "Error " + e;
}
<lightning-checkbox-group
class="slds-box"
label="Select a color"
options={options}
value={acc_array}
onchange={handleValidity}