the validation isn't working in my formRow directive. I put a ng-form with the field name in the directive, but the [[ field ]].$invalid for example will not triggered. Does anybody know why?
Directive:
<li class="form__row" ng-form="[[ field ]]">
<div class="label">
<label ng-class="{ 'required' : required == 'true' }" for="frm-[[ field ]]">[[ label ]]</label>
</div>
<div class="field" ng-switch="required" ng-class="{ 'field--invalid' : [[ field ]].$touched && [[ field ]].$invalid, 'field--valid': [[ field ]].$touched && [[ field ]].$valid }">
<input ng-switch-when="true" type="[[ type ]]" name="[[ field ]]" id="frm-[[ field ]]" ng-model="record[ field ]" required>
<input ng-switch-default type="[[ type ]]" name="[[ field ]]" id="frm-[[ field ]]" ng-model="record[ field ]" >
</div>
Directive.js
.directive('formRow', function () {
return {
restrict: 'EA',
templateUrl: FW.Config.submap + 'angular/_directives/formRow.html',
replace: true,
scope: {
record: '=',
type: '@',
field: '@',
label: '@',
required: '@'
},
link: function($scope, element, attr) {
// Wordt gezet bij form submit
$scope.$on('record:invalid', function() {
$scope[$scope.field].$setTouched;
});
}
}
})
Call from template:
<form name="formData" ng-submit="submit($event)" class="form--wide frm-login" novalidate>
<ul>
<form-row record="inloggen" field="emailadres" label="E-mailadres" type="email" required="true"></form-row>
<form-row record="inloggen" field="wachtwoord" label="Wachtwoord" type="password" required="true"></form-row>
</ul>
By the way: I use square brackets as $interpolateProvider symbols, because of the use of twig also in my templates.