Home > Blockchain >  Kendo UI Grid form validation throwing undefined error
Kendo UI Grid form validation throwing undefined error

Time:02-02

I am creating a sample Kendo form in angular where I am using add or update button to save the data. While adding the button, I'm trying to disable it if the form is invalid but it is throwing me error as below.

App.component.html form button save code:

<button kendoGridSaveCommand [disabled]="formGroup?.invalid">
            {{ isNew ? "Add" : "Update" }}
          </button>

Error is throwing at "disabled" and "invalid"

Error at disabled:

Type 'boolean undefined' is not assignable to type 'boolean'. Type "undefined' is not assignable to type 'boolean'. ngtsc(2322)

Error at invalid:

The left side of this optional chain operation does not include 'null' or "undefined' in its type, therefore the '?.' operator can be replaced with the '.' operator. ngtsc(-998107)

Please help me on this.

CodePudding user response:

When you're using ?. you basically get a new type with three states. The disabled input expects a simple boolean. You can do the following:

[disabled]="!!formGroup?.invalid"

This will leave true and false alone but will convert any falsy, like undefined, to false.

  • Related