I have built a custom angular component to select multiple elements from a collection. This custom element has an array as ngModel. I would like it to reflect the validation state, i.e : ng-invalid ng-invalid-required.
if I add in the tpl of the custom element an input field with this ngModel, the validation state is updated correctly. But if it is on the wrapping div of this custom element, it does not work:
<input type="text" ng-model="$ctrl.selected" name="selected" required /><!--WORKS-->
<div
class="pseudoField"
ng-model="$ctrl.selected"
required
name="test"
><!--NOT WORKING-->
If the form that contains that custom element gets submitted, the validation state is corrrectly reflected on the input. It gets the css classes : "ng-invalid ng-invalid-required." But the same thing does not happend on the div.
How to make this happend on the div ?
EDIT: To give some context, the component is an autocomplete-dropdown thing, that allows to select multiple element from a list presented in a dropdown. Once selected, the item gets in a list of selected items, presented like "tags". It is similar to select2 "Tagging support" example : https://select2.github.io/examples.html
To achieve that I have wrapped an input in a container div ".pseudoField". When the container div is clicked, it passes the focus to that input element. The input has its border styling removed, so it is "invisible". When the input is focused, the styling of div.pseudoField is changed to make it look like it is focused. That way, for the user the div.pseudoField acts like a form element, and I would like it to also have the validation state. Hope that makes sense.