Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 - Removing disabled attribute from element

I have a form that is using a directive called ng-select which enhances select inputs. In my setup, I allow a user to make some selections and then click on a "Filter" button.

Upon clicking this button, I disable the input.

HTML:

<div class="form-group">
   <div class="input-group">
      <ng-select #cc formControlName="costCenter" (removed)="updateChoices(cc.active, 'costCenter')" [allowClear]="true" [multiple]="true"
      [items]="getCostCenters()" placeholder="Select one or more Cost Centers">
      </ng-select>
      <span class="input-group-btn">
      <button #b_cc class="btn btn-sm btn-default" type="button" title="Update Filter" (click)="updateChoices(cc.active, 'costCenter', cc, b_cc)"><i class="fa fa-filter"></i></button>
      </span>
   </div>
</div>

Component Function:

    /**
     * Upon selecting a data point, reload available options 
     * based on data selected.
     * 
     * @param formValues 
     * @param field 
     */
    updateChoices(formValues, field, selectInput, button): void {

        // Show the loading indicator
        this.showLoader = true;

        // Set and fetch data
        this.selectedFields[field] = formValues;
        this.getFields(this.selectedFields, false);

        // Disable our search field and filter button
        button.disabled = true;
        selectInput.disabled = true;

    }

You can see in the component that I am disabling both the field and the button that they clicked on.

I am now trying to implement a reset method where I can reset all of the fields back to empty, including toggling them to enabled.

I tried doing it through my reactive form by using this.importForm.controls['costCenter'].enable(); but that didn't do anything.

I inspected the form after reset and it gets set back to pristine and not touched, so I know my form reset is working, the re-enabling is not though.

I have also tried to do this in my form reset method as such:

this.importForm.reset({
  costCenter: {value:[], disabled:false},
});

What am I missing here?

like image 728
SBB Avatar asked Jan 04 '23 14:01

SBB


1 Answers

Apparently solution to this is here.

This worked for me

<input [attr.disabled]="IsTextBoxDisabled?'true':null">
like image 158
Temp O'rary Avatar answered Jan 18 '23 09:01

Temp O'rary