I'm having trouble understanding why my directive isn't updating the disabled state of elements when there is a change in the model. Can someone help me identify the issue?
import { DirectiveOptions } from 'vue';
const disableAllDirective: DirectiveOptions = {
componentUpdated: function (el, binding) {
if (!binding.value) return;
const tags = ["input", "button", "textarea", "select"];
tags.forEach(tagName => {
const nodes = el.getElementsByTagName(tagName);
for (let i = 0; i < nodes.length; i++) {
(<HTMLInputElement>nodes[i]).disabled = true;
(<HTMLInputElement>nodes[i]).tabIndex = -1;
}
});
}
};
export default disableAllDirective;
This is how I'm using the directive:
<div class="col-5" v-disableAll="!selectedBusinessId">
<div class="form-row">
<label class="col-1 pt-1 col-form-label-sm">Search:</label>
<div class="col-6 form-inline">
<input id="txtClientSearch" @change="searchClients" v-model.lazy="clientSearchTerm" placeholder="Facility / Client Name" class="form-control" autocomplete="off" />
<input id="txtClientIdSearch" @change="searchClients" v-model.lazy="clientIdSearch" v-validate="'between:1,32767'" data-vv-as="Customer Number" placeholder="Number" class="form-control number-without-spinner" autocomplete="off" type="number" />
<button v-on:click="searchClients" class="btn btn-outline-secondary btn-sm form-control-xsm"><i class="fa fa-search"></i></button>
<button v-on:click="onClearSearchClick" class="btn btn-outline-primary btn-sm form-control-xsm"><i class="fa fa-times"></i></button>
</div>
<div class="col-auto form-check form-check-inline checkbox checkbox-primary">
<input v-model="showInactiveClients" v-on:change="searchClients" id="chkInactive" class="form-check-input" type="checkbox" value="inActive">
<label class="form-check-label no-padding" for="chkInactive">Show Inactive</label>
</div>
</div>
</div>