Implementing the TokenInput plugin alongside AngularJS formController validation.
Currently, I am working on verifying if a field contains text and then marking it as valid. However, the complication arises from the plugin creating its own input along with ul+li for styling.
With access to addItem (formname) and controller capabilities, the goal is to set it to $valid.
Markup.
<form class="form-horizontal add-inventory-item" name="addItem">
<input id="capabilities" name="capabilities" token-input data-ng-model="inventoryCapabilitiesAutoComplete" data-on-add="addCapability()" data-on-delete="removeCapability()" required>
<div class="required" data-ng-show="addItem.capabilities.$error.required" title="Please enter capability."></div>
</form>
JavaScript.
$scope.capabilityValidation = function (capability) {
if (capability.name !== "") {
addItem.capabilities.$valid = true;
addItem.capabilities.$error.required = false;
} else {
addItem.capabilities.$valid = false;
addItem.capabilities.$error.required = true;
}
};
The capabilityValidation function is triggered when the TokenInput has an entry and the object is passed in.
UPDATE:
Realized that ng-model on my input performs actions and retrieves autocomplete results, making it challenging to achieve ng-valid functionality since it depends on the model.
$scope.inventoryCapabilitiesAutoComplete = {
options: {
tokenLimit: null
},
source: urlHelper.getAutoComplete('capability')
};
This autocomplete implementation was not authored by me. Is there an alternative approach where I can manipulate the ng-model attribute and relocate the model function elsewhere?