Search Posts

Category: validation

angular schema form image upload accepting all file types

I have used the this plugin Angular Schema Form and all the things are working as expected but for image upload i need to have validations so as to allow the users input only images. although the schema contains an accept attribute in the properties for image upload as follows: { “type”: “object”, “properties”: { “text1”: { “type”: “string”, “title”: “Untitled Text field”, “name”: “text1”, “url”: “http://localhost/image/upload/img59b7c29f1622b.jpeg” }, “file2”: { “type”: “object”, “format”: “file”, “title”: […]

AngularJS – dynamic validation using $valid

I’m using AngularJS to validate a form, and I have this button to submit. <button type=”submit” ng-disabled=”btn” ng-click=”submit(settings.$valid)” class=”btn btn-primary”> Submit </button> This button is disabled whenever the form is invalid, but once it’s valid, the button is enabled. So this is my code $http.get(“http://localhost:5000/settings”).then(function(response){ $scope.numberOfRows = response.data.numberOfRows console.log($scope.numberOfRows) if($scope.numberOfRows==0 && $scope.settings.$valid == false ){ $scope.btn=true }else if($scope.numberOfRows==0 && $scope.settings.$valid == true){ $scope.btn=false } if($scope.numberOfRows==1){ $scope.btn=true } }) My problem is when the numberOfRows = […]

angular material md-select ng-model set to undefined rules

When I execute this script, aForm.aField.$error contains {“required”:true} BUT $scope.fruit is not set to undefined even though it is not in the md-option values. So the “required” validation is done but not the set to undefined. <!doctype html> <html ng-app=”anApp”> <head> <link rel=”stylesheet” href=”bower_components/angular-material/angular-material.min.css”> <script src=”bower_components/angular/angular.js”></script> <script src=”bower_components/angular-messages/angular-messages.min.js”></script> <script src=”bower_components/angular-material/angular-material.js”></script> <script src=”bower_components/angular-animate/angular-animate.min.js”></script> <script src=”bower_components/angular-aria/angular-aria.min.js”></script> <script> angular.module(‘anApp’, [‘ngMessages’, ‘ngMaterial’]) .controller(‘aController’, function ($scope, $timeout) { $scope.fruitBasket = [{name:”apple”, id:1}]; $scope.fruit = 100; $scope.required = true; }); </script> […]

Form validation in angularjs doesn’t work

I wrote a form validation in angularjs but it does not work. When I send form with empty fields form has class ‘ng-valid’ and ‘ng-hide’ doesn’t remove from error. <form name=”form” ng-submit=”createUser(user)” novalidate> <div class=”form-group”> <label for=”name”>Nazwa użytkownika:</label> <input type=”text” name=”name” id=”name” class=”form-control” ng.model=”user.name” required=””> <div ng-show=”form.$submitted || form.name.$touched”> <div ng-show=”form.name.$error.required”>Podaj nazwę użytkownika.</div> </div> </div> <div class=”form-group”> <label for=”email”>Adres e-mail:</label> <input type=”email” name=”email” id=”email” class=”form-control” ng.model=”user.email”> <div ng-show=”form.$submitted || form.email.$touched”> <span ng-show=”form.email.$error.required”>Podaj adres e-mail.</span> <span […]