angular-form2

by bullrout

HTML

<html ng-app="myapp">
<body ng-controller="myappCtrl">
    
    <select ng-model="selectValue" ng-options="opt.val as opt.lbl for opt in opts" ng-change="selectChanged()"/>
    <input type="text" ng-model="textValue"/>
    <span style="color:red" ng-show="textError" ng-bind="textError">Error!</span>
    <button ng-click="submit()">Submit</button>
    
</body>
</html>

JavaScript

angular.module('myapp', []).controller('myappCtrl', function($scope) {
    $scope.opts = [{val:1, lbl:'One'},
                   {val:2, lbl:'Two'},
                   {val:3, lbl:'Three'}];
    $scope.selectChanged = function() {
        $scope.textValue = '';
    };
    
    $scope.submit = function() {
        if ($scope.textValue.length > 10)
            $scope.textError = "Too long!";
           
    };
});