add class when input is valid in angularjs

add class when input is valid in angularjs

By : Sonnet
Date : November 29 2020, 09:01 AM
fixed the issue. Will look into that further The $valid and $invalid properties come from the form and not from the value of the input. You need a form element with a name, then also a name into the input, and then use formName.inputName.$valid or $invalid.
code :

Share : facebook icon twitter icon
AngularJS: How do I manually set input to $valid in controller?

AngularJS: How do I manually set input to $valid in controller?

By : 김영민
Date : March 29 2020, 07:55 AM
I wish this help you You cannot directly change a form's validity. If all the descendant inputs are valid, the form is valid, if not, then it is not.
What you should do is to set the validity of the input element. Like so;
code :
addItem.capabilities.$setValidity("youAreFat", false);
addItem.capabilities.errors.youAreFat == true;
angularjs - ng-dirty class on input type number / $valid is true when entering text

angularjs - ng-dirty class on input type number / $valid is true when entering text

By : vinesh maurya
Date : March 29 2020, 07:55 AM
help you fix your problem It's browser "bug"(it's actually expected behaviour) see https://github.com/angular/angular.js/issues/2144 there are some workarounds, such as this https://groups.google.com/forum/#!topic/angular/pRc5pu3bWQ0/discussion
or you could write your own input directive using the same principles
code :
app.directive('input', [function() {
    return {
        restrict: 'E',
        require: '?ngModel',
        link: function(scope, el, attrs, ctrl) {
            if (attrs.type == 'number' && typeof el.prop('validity') !== 'undefined') {
                el.on('keyup change', function() {
                    var validity = el.prop('validity');
                    ctrl.$setValidity('badInput', !validity.badInput);                      
AngularJS input watch $valid or $error

AngularJS input watch $valid or $error

By : user3439145
Date : March 29 2020, 07:55 AM
may help you . I don't see any reason why your first variant shouldn't work.
code :
<div ng-app="myApp">
    <div data-ng-controller="MainController">
        <form name="myForm"> 
            <input name="myInput" ng-model="myInputMdl" business-validation />
var myApp = angular.module('myApp', []);

myApp.controller('MainController', function ($scope) {
    $scope.$watch('myForm.myInput.$valid', function (validity) {
        console.log('valid', validity);

myApp.directive('businessValidation', function () {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, elem, attr, ctrl) {
            function validate (input) {
                return input === 'hello';

            ctrl.$parsers.unshift(function (value) {
                var valid = validate(value);
                ctrl.$setValidity('businessValidation', valid);
                return valid ? value : undefined;

            ctrl.$formatters.unshift(function (value) {
                ctrl.$setValidity('businessValidation', validate(value));
                return value;
AngularJS input $valid is always false with no error

AngularJS input $valid is always false with no error

By : Nontombie
Date : March 29 2020, 07:55 AM
it fixes the issue I'm trying to apply an AngularJs validation in my project. So the following code was written: , I had the same issue. It works if you use the $scope:
code :
<span>valid = {ng $scope.recipeTitle.name.$valid ng}</span>
<span>errors = {ng $scope.recipeTitle.name.$error ng}</span>
<span>valid = {ng recipeTitle.name.$valid ng}</span>
<span>errors = {ng recipeTitle.name.$error ng}</span>
AngularJS Input valid if value is in array

AngularJS Input valid if value is in array

By : erik harlert
Date : March 29 2020, 07:55 AM
I wish this help you Check Angular-UI's project which includes ui-validate/ui-validate-async directives.
This directives makes it very easy to create custom validator expressions. In your case it can look like ui-validate="{inArray: 'isInMyArray($value)' }".
Related Posts Related Posts :
  • CRM 2013 Limit the date field
  • fancybox - changing close button color
  • Ember-notify giving error can't read property "Service" of undefined
  • Passport-init.js authentication is not working in nodejs
  • Branch.io Cordova API - init() fails on Android Device
  • appending HTML codes to an elements using js
  • Css animation to extend button text on hover
  • I want to restrict HTML input autocomplete to 3 letter minimum
  • tinyMCE editor not updating on the fly
  • typescript kendo-ui call method from string
  • HttpCompileException was unhandled by user code (when i am adding c# code in script)
  • Send form data as array of objects to controller in asp.net mvc
  • Javascript, multi file modules and Require.Js
  • how to render a complete new template and leave the application template in ember
  • Hover unrelated divs
  • Permute string until it matches some input?
  • How to fire JQuery change event when input value changed programmatically?
  • AJAX: POST data to a different url
  • checkbox column in jquery datatable
  • Document.evaluate for documents without namespaceURI crashes Microsoft Edge
  • Bootstrap Menu with "More" option Responsive issue
  • Standard inputs not being added to Angularjs Form $Scope
  • Express promise throw error
  • onclick and get in jquery
  • How to get the country code from Google Places API
  • Passing parameters url in Select2
  • Is there any frame work for Marklogic to write javascript code?
  • How to implement a boostrap template over bootstrap-sass gem
  • Why fixed div comes out when horizontally scrolled?
  • How to limit scope of a function in javascript/ jquery
  • Overlapping legend d3.js
  • Apply transition to div
  • Javascript game help - counting with dice
  • How to hide a div from angular controller
  • Can Promise load multi urls in order?
  • How enable Hover event for bootstrap menus?
  • D3 scale.invert() isn't returning date for x
  • Parsing object to array using underscore js or lodash
  • ES6 with React and Browserify
  • AngularJS Factory return type undefined
  • javascript follow html input fields
  • how to declare a double array in javascript for this particular UI
  • Jquery : find length of mixed list
  • Returning the array before the function is complete & Angular JS
  • Javascript set value of class & hidden input in nested divs
  • Register custom filters with vue.js
  • Add class to input parent
  • Angular controller not talking to view
  • Trouble creating "if then" Javascript statement to change background color of page
  • Socket.IO - Middleware and scoping: how should I access global IO object from external middleware?
  • Positioning multiple div elements
  • Checkbox clicking works, deselecting checkbox not working Javascript
  • Adding ajax jQuery File upload
  • Creating a dynamic array within a dynamic array in JQuery
  • Multiple File Upload actions for a single File Input PHP/JS
  • Want to move an added element to a different part of the DOM
  • Why can't I get Angularjs to work?
  • Minimizing browser window in Firefox & Chrome adds white space to right of page
  • I need to insert the date and time of employee stamp in and out into mysql database
  • Making css auto slider
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co