JSFiddle - React, Tailwind, and code Playground

by Michael Piecko

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>
        <button ng-click="validateField()">Validate 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) {
    $scope.customer = {
        fullName: ''
    };
    
    $scope.invalidateField = function() {
        $scope.myForm.fullName.$setValidity('invalid', false);
    };
    
    $scope.validateField = function() {
        $scope.myForm.fullName.$setValidity('invalid', true);
    }
};