简体   繁体   English

具有切换值的多个复选框

[英]Multiple Checkbox with Toggle Value

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例如,考虑三个复选框 1、2 和 3

If I select on the 1 checkbox other two checkbox should need to be enable (2, 3).如果我选择 1 复选框,则需要启用其他两个复选框(2、3)。

If I change to false (1) then other two checkbox need to be disable (2, 3).如果我更改为false (1),则需要禁用其他两个复选框 (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.另一个条件是,如果我取消选中复选框 (1),那么其他两个复选框值应该需要重置 false (2, 3) 并需要禁用。

I have done with above condition.我已经完成了上述条件。 However, what is the problem is the value is not get updated in ngmodel .但是,问题是值没有在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 .输入传递true true false

So, here I am passing true for 1, true for 2, and false for 3 which is two way binding.所以,在这里我传递true 1, true为2,和false 3这是双向绑定。

If I change the 3 to true then 2 got unchecked but value is not changing如果我将 3 更改为true则 2 未选中但值未更改

Here is my sample json.这是我的示例 json。

Before:前:

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

After check the 2ed:检查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}

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.我希望我理解你的意思,我用stackblitz做了一个例子,如果你需要这样说,我会解释更多。

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.简短说明 - 我使用[disabled]属性来启用/禁用输入,然后我使用(change)事件来清除变量的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM