2

I am using a checkbox and I hope it is never checked.

I used a function for this, but it is not working, if you check the checkbox a few times it is active (checked).

How can I keep it always unchecked?

DEMO

.TS

check: boolean = false;

change(e){
  this.check = false
}

.HTML

<ul class="mdc-image-list my-image-list" style="margin-top:120px;padding-left: 10px;padding-right: 10px;">
    <ng-container *ngFor="let product of data; let  j = index;">
        <li class="mdc-image-list__item">
            <div class="mdc-image-list__image-aspect-container">
                        <img [src]="product.image" class="mdc-image-list__image">
            </div>
            <div class="mdc-image-list--with-text-protection">
                <div class="mdc-image-list__supporting mdc-image-list__supporting">
                    <span class="mdc-image-list__label">{{product.name}}</span>
                </div>
                <div class="Info">
                    <dx-check-box (onValueChanged)="change($event);" [(value)]="check"></dx-check-box>
                </div>
            </div>
        </li>
    </ng-container>
</ul>

Problem

enter image description here

mark
  • 105
  • 1
  • 9

2 Answers2

1

You can use [ngModel] binding to display the check value and (ngModelChange) event handling to process the change:

<dx-check-box [ngModel]="check" (ngModelChange)="change($event)"></dx-check-box>

In the event handler:

  1. Set the new check value
  2. Force change detection by calling ChangeDetectorRef.detectChanges
  3. Set the check value back to false
change(value) {
  this.check = value;
  this.changeDetectorRef.detectChanges();
  this.check = false;
  ...
}

See this stackblitz for a demo.

ConnorsFan
  • 70,558
  • 13
  • 122
  • 146
0

I've tried simple

<dx-check-box [value]="false"></dx-check-box>

But for me it doesn't worked.

Seems to be a bug or something.

Workaround options are:

  1. <dx-check-box [value]="false" [disable]="true"></dx-check-box> - working, and looking a bit differently, but you can set up some styles in css to make it look as it's not disabled

  2. paint transparent div over the checkbox, it prevents input from being clicked

qiAlex
  • 4,290
  • 2
  • 19
  • 35