1

My requirement is to have a three check box with some certain condition which clicking on the checkbox.

For example, consider three check box 1, 2, and 3

If I select on the 1 checkbox other two checkbox should need to be enable (2, 3).

If I change to false (1) then other two checkbox need to be disable (2, 3).

And another condition, if I unchecked the checkbox (1) then other two checkbox value should need to reset false (2, 3) and need to disable.

I have done with above condition. However, what is the problem is the value is not get updated in ngmodel.

Below sample code

 <td>
              <div class="col-lg-12" id="radiobutton">
                  <input #EDIsRead=ngModel [(ngModel)]="GetRoleIsRead.EDIsRead" name="GetRoleIsRead.EDIsRead" class="form-check-input col-sm-2"
                  type="checkbox" id="EDIsRead" style="padding-left: 0px !important;" (change)="CheckeventforRead('ED')">
              </div>
            </td>
            <td>
              <div class="col-lg-12" id="radiobutton">
                  <input #EDIsModifyLOB=ngModel [(ngModel)]="GetRoleIsModifyLOB.EDIsModifyLOB" name="GetRoleIsModifyLOB.EDIsModifyLOB" class="form-check-input col-sm-2"
                  type="checkbox" id="EDIsModifyLOB" style="padding-left: 0px !important;" (change)="CheckeventforModifyLOB('ED','0')">
              </div>
            </td>
            <td>
              <div class="col-lg-12" id="radiobutton">
                  <input #EDIsModifyAll=ngModel [(ngModel)]="GetRoleIsModifyAll.EDIsModifyAll" name="GetRoleIsModifyAll.EDIsModifyAll" class="form-check-input col-sm-2"
                  type="checkbox" id="EDIsModifyAll" style="padding-left: 0px !important;" (change)="CheckeventforModifyAll('ED','0')">
              </div>
            </td>`

Input passing true true false.

So, here I am passing true for 1, true for 2, and false for 3 which is two way binding.

If I change the 3 to true then 2 got unchecked but value is not changing

Here is my sample json.

Before:

{"GetRoleIsRead.EDIsRead": true, "GetRoleIsModifyLOB.EDIsModifyLOB": false, "GetRoleIsModifyAll.EDIsModifyAll": true }

After check the 2ed:

{"GetRoleIsRead.EDIsRead": true, "GetRoleIsModifyLOB.EDIsModifyLOB": true, "GetRoleIsModifyAll.EDIsModifyAll": true }

Actual output should need to be:

{"GetRoleIsRead.EDIsRead": true, "GetRoleIsModifyLOB.EDIsModifyLOB": true, "GetRoleIsModifyAll.EDIsModifyAll": false}
1
  • this is trivial if you were to use reactive forms, you would add (change) events to trigger changes. do you want example or are you definately using template forms no matter what? Commented May 2, 2019 at 7:20

1 Answer 1

1

I hope I understood your meaning, I made an example with stackblitz if this is what you need just say that, and I will explain it more.

A short explanation - I used [disabled] property in order to enable/disable inputs, then I used (change) event to clear the values of the variables.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Michal. I have done with the same logic using jquery by picking the value fro m hidden textbox.
@AravindhanR Happy to hear that it helped you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.