GithubHelp home page GithubHelp logo

benmj / angular-bootstrap-show-errors Goto Github PK

View Code? Open in Web Editor NEW

This project forked from paulyoder/angular-bootstrap-show-errors

0.0 1.0 0.0 206 KB

An Angular directive for Bootstrap to intelligently show form validation errors

License: MIT License

angular-bootstrap-show-errors's Introduction

Angular Bootstrap Show Errors

An Angular directive for Bootstrap 3 that intelligently applies the 'has-error' class to invalid form fields.

See the Bootstrap Form Validation Done Right in AngularJS blog post to read about the benefits of using this directive.

Installation

With Bower

bower install angular-bootstrap-show-errors

Manually

Copy the src/showErrors.js or src/showErrors.min.js file into your project.

Quick Start

  1. Include the ui.bootstrap.showErrors module in your Angular app
  2. Add the show-errors attribute on the form div element that contains the form-group class
<form name="userForm">
  <div class="form-group" show-errors>
    <input type="text" name="firstName" ng-model="firstName" ng-required />
  </div>
</form>

Force Validity Check

By default this directive doesn't check the validity until the user tabs off the input element. However, there are times you want to show invalid form elements even if the user has not tabbed off. (e.g. before saving the form)

To force the validity check, broadcast the show-errors-check-validity event.

Example

<form name="userForm">
  <div class="form-group" show-errors>
    <input type="text" name="firstName" ng-model="firstName" ng-required />
  </div>
  <input type="submit" ng-click="save()" />
</form>
$scope.save = function() {
  $scope.$broadcast('show-errors-check-validity');
  
  if ($scope.userForm.$valid) {
    // save the user
  }
}

Reset

If you have functionality to reset your form, you can broadcast the 'show-errors-reset' event to remove any errors on the form elements.

Example

<form name="userForm">
  <div class="form-group" show-errors>
    <input type="text" name="firstName" ng-model="firstName" ng-required />
  </div>
  <a href="#" ng-click="reset()">Reset</a>
</form>
$scope.reset = function() {
  $scope.$broadcast('show-errors-reset');
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.