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?
Apparently solution to this is here.
This worked for me
<input [attr.disabled]="IsTextBoxDisabled?'true':null">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With