Skip to content

Behaviour state change of switch even if value not change. #36

@Dhairya312

Description

@Dhairya312

Bug Report or Feature Request.

#Issue# ###Angular 7#
Here switch in html section:-
<bSwitch
[(ngModel)]="branch.isDefault"
formControlName="isDefault"
[switch-on-text]="'YES'"
[switch-off-text]="'No'"
[switch-size]="'mini'"
(changeState)="onBranchDefault($event)">

{{branch.isDefault}}

Here is Ts code:-
onBranchDefault(i: number, event: {currentValue: boolean, previousValue: boolean}) {
this.data.branchDetails[i].isDefault = false;
const defaultBranch = this.data.branchDetails.find((def) => def.isDefault);
if (event.currentValue) {
if (defaultBranch) {
const confirmIS = confirm('Are sure want to override Default Branch?');
if (confirmIS) {
this.data.branchDetails[i].isDefault = true;
let previousDefaultBranch = this.data.branchDetails.indexOf(defaultBranch);
this.data.branchDetails[previousDefaultBranch].isDefault = false;
return;
}
return;
}
this.data.branchDetails[i].isDefault = true;
}
}

when confirmation is cancel the value which bind with [(ngModel)] will remain same but the Behaviour of the switch changes,
like if the switch is false that time on click the confirm message open that time when event get cancel the value will remain false but the behaviour of the switch is set to true.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions