1 year ago

#263769

test-img

Sofi

Disabled checkbox(es) in Angular formyl

How can I disable the checkbox without displaying this warning message?

"It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true. when you set up this control in your component class, the disabled attribute will actually be set in the DOM for you. We recommend using this approach to avoid 'changed after checked' errors."

This is my html code:

<ng-container *ngFor='let option of to.options' >
      <p-checkbox class='p-checkbox-label'
        [formControl]='formControl'
        [inputId]='option.key'
        [name]='to.key'
        [label]='option.label'
        [value]='option.key'
        [disabled]='option.disabled'
      ></p-checkbox>
</ng-container>

This is the code to create two checkboxes, where the second checkbox field is disabled

form: new FormGroup({}),
fields: [
      {`enter code here`
        key: 'value',
        type: 'checkbox-group',
        templateOptions: {
          options: [
            {
              key: 'selected',
              label: 'Selected',
              disabled: false
            },
            {
              key: 'selectedDisabled',
              label: 'Selected - Disabled',
              disabled: true
            }
          ]
        },
        hooks: {
          onInit: (field: any) => {
            field.form.setValue({
              'value': ['selected', 'selectedDisabled']
            });
          }
        }
      }
   ]

angular

angular-formly

0 Answers

Your Answer

Accepted video resources