JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.12/angular.min.js"></script>
<div ng-app>
<div ng-controller="formTest">
<h3>Steps to reproduce behavior</h3>
<ul>
<li>Watch the "Debug Model" output below</li>
<li>Type something in the field</li>
<li>Press "Invalidate Field" button</li>
<li>Type something in the field again</li>
</ul>
<form name="myForm">
<input type="text" name="fullName" ng-model="customer.fullName"/>
</form>
<button ng-click="invalidateField()">Invalidate Field</button>
<table>
<tr>
<td>
<h3>Debug Model</h3>
<pre>{{ customer | json }}</pre>
</td>
<td>
<h3>Debug Form</h3>
<pre>{{ myForm | json }}</pre>
</td>
</tr>
</table>
</div>
</div>
CSS
body {
font-family: sans-serif;
}
td {
width: 50%;
vertical-align: top;
}
.ng-invalid {
border-color: red;
}
JavaScript
function formTest($scope, $timeout) {
$scope.customer = {
fullName: ''
};
$timeout(function() {
$scope.myForm.fullName.$parsers.push(function(value) {
var valid = value.indexOf('-') < 0;
$scope.myForm.fullName.$setValidity('invalid',
valid);
return valid ? value : undefined;
});
});
};