Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dhairya312 opened this issue Jan 22, 2021 · 0 comments
Open

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

Dhairya312 opened this issue Jan 22, 2021 · 0 comments

Comments

@Dhairya312
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant