Note that there are some explanatory texts on larger screens.

plurals
  1. POangular.js validation of the javascript
    primarykey
    data
    text
    <p>At the moment this is my code:</p> <pre><code>&lt;!doctype html&gt; &lt;html ng-app="validation-example"&gt; &lt;head&gt; &lt;script src="http://code.angularjs.org/1.0.6/angular.min.js"&gt;&lt;/script&gt; &lt;link href="http://docs.angularjs.org/css/bootstrap.min.css" rel="stylesheet" /&gt; &lt;link href="http://docs.angularjs.org/css/font-awesome.css" rel="stylesheet" /&gt; &lt;link href="http://docs.angularjs.org/css/docs.css" rel="stylesheet" /&gt; &lt;link href="StyleSheet.css" rel="stylesheet" /&gt; &lt;script src="script.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body style="background-color: teal"&gt; &lt;link href="StyleSheet.css" rel="stylesheet" /&gt; &lt;div ng-controller="Controller"&gt; &lt;form name="form" class="css-form" novalidate&gt; Float: &lt;input type="text" ng-model="length" name="length" smart-float /&gt; {{length}}&lt;br /&gt; &lt;span ng-show="form.length.$error.float"&gt;This is not a valid float number!&lt;/span&gt; &lt;br /&gt; &lt;button ng-click="submit()" ng-disabled="form.$invalid"&gt; Submit&lt;/button&gt; &lt;/form&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And js</p> <pre><code>var app = angular.module('validation-example', []); function Controller($scope) { $scope.master = {}; $scope.reset = function () { $scope.user = angular.copy($scope.master); }; $scope.reset(); $scope.submit = function () { debugger; if (form.$invalid) { alert("sss"); } }; } var FLOAT_REGEXP = /^\d+((\.|\,)\d+)?$/; app.directive('smartFloat', function () { return { require: 'ngModel', link: function (scope, elm, attrs, ctrl) { ctrl.$parsers.unshift(function (viewValue) { if (FLOAT_REGEXP.test(viewValue)) { ctrl.$setValidity('float', true); return parseFloat(viewValue.replace(',', '.')); } else { ctrl.$setValidity('float', false); return undefined; } }); } }; }); </code></pre> <p>And i have the button disabled when the float is invalid. However i want to always enable the submit button and on the server in the function to check if the form is invalid and to pop an alert to the user that the submit is interrupted because we have invalid data. When applying class binding i can "form.$invalid", but if i remove it in order to allow invalid submit then in the function if (form.$invalid) is undefined. How to check in the controller if i have invalid inputs in the form? I can loop through the elements and check for ng-invalid css class but this is the most dumiest think so please suggest a smart solution.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload