npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pretty-form-error

v2.0.5

Published

Javascript plugin that makes pretty the form errors in all browsers by applying the same styles

Downloads

13

Readme

prettyFormError

By default all major browsers have their own CSS styles for the error messages shown when a form is submitted and some of the fields are empty or with a wrong value.

With this jQuery plugin you can show identical styles for the errors in all major browsers.

In order to have a custom look for the bubbles across all supporting browsers the only option is to suppress the default bubble and implement your own.

Try it @ https://byverdu.github.io/prettyFormError/

Good to know

The required attribute is a must in all the elements that you need to validate.

When you have to validate a group of <input type="radio" name="group-1"> they must have the same attribute name

The select element needs to have an empty option element as the first element so it can get an error if none of the other options are selected

Within HTML5 you can add an extra layer of validation by using the appropiate value for the type attribute used in the input tag.

Using the required attribute for a group of check boxes fails because when you submit the form the error message pops up for the unchecked boxes.

To solve this issue you need to add/remove the required attribute programmatically. This plugin provides an option that lets you pass the problem.

Google knows everything, checkbox issue

This is how your error messages will look after using this plugin.

Dependencies

jQuery or not :smile:

How to use the plugin

You will only need prettyFormError.min.js and prettyFormError.min.css.

You can grab them on unpkg CDN and use it like this:

<link rel="stylesheet" href="https://unpkg.com/pretty-form-error@check_latest_version/dist/prettyFormError.css" media="screen">
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="https://unpkg.com/pretty-form-error@check_latest_version/dist/prettyFormError.min.js"></script>  

or found them under /dist/** folder and use it like this:

<link rel="stylesheet" href="prettyFormError.min.css" media="screen">
<script src="https://code.jquery.com/jquery-3.1.1.js"></script>
<script src="prettyFormError.min.js"></script>  

or use npm to install the plugin and require the module within your project.

const prerttyError = require( 'pretty-form-error' );

prettyFormError( 'form', {options});

It is really simple to use it, just select your form with plain JS or jQuery and call the prettyFormError method.

// plain Js
prettyFormError('myFormSelector', optionalOpts);

// jQuery version
$('myFormSelector').prettyFormError(optionalOpts);

How to use it with React

class App extends PureComponent {
  componentDidMount() {
    const prettyErrorOptions = {
      classError: 'prettyFormError-black'
    }
    prettyError( 'form', prettyErrorOptions );
  }
  render() {
    return(
      <Fragment>
        <h1>prettyForm in React</h1>
        <form>
          <input type="text" required/>
          <button>Click</button>
        </form>
      </Fragment>
    );
  }
}

How to use it with Angular

angular.module('playground', [])
  .directive('prettyForm', function () {
    // Create a directive
    return {
      restrict: 'A',
      link: function (scope, element, attrs) {
        prettyFormError('form', scope.prettyErrorOptions);
      }
    };
  })
  .controller('prettyFormCtrl', function ( $scope ) {
    $scope.title = 'prettyForm in Angular';
    $scope.prettyErrorOptions = {
      classError: 'prettyFormError-black'
    };
  });
<body ng-app="playground">
  <section ng-controller="prettyFormCtrl">
    <h1>
      {{title}}
    </h1>
    <!-- Use the directive -->
    <form pretty-form>
      <input required type="text" />
      <button>Submit</button>
    </form>
  </section>
</body>

Plugin Options.

The plugin is initialized with the following default options:

{
  multiCheckbox: {
    enabled: false
  },
  classError: 'prettyFormError',
  positionMethod: 'after',
  elementError: 'div',
  callToAction: 'button',
  focusErrorOnClick: true,
  fadeOutError: {
    fadeOut: false
  }
}

multiCheckbox[Object]

Use this option if you need to validate a group of checkboxes. disabled by default!!

{
    multiCheckbox: {
      enabled: true,
      selector: '.commonClassForGroup'
    }
}
<p>Best topping ever</p>

<label for="pineapple">Pineapple:</label>
  <input required class="commonClassForGroup" type="checkbox" value="pineapple">

<label for="ham">Ham:</label>
  <input required class="commonClassForGroup" type="checkbox" value="ham">

<label for="olives">Olives:</label>
  <input required class="commonClassForGroup" type="checkbox" value="olives">

classError[String]

Name for the css class used for the error messages. The default one is prettyFormError but you could also use prettyFormError-black or prettyFormError-white

positionMethod[String]

Where do you want to display the error, after or before the errored input.

elementError[String]

HTML element that you want to use for wrap the errors.

callToAction[String]

HTML selector used to submit the form.

focusErrorOnClick[Boolean]

Use false if you want to disable this otpion.

fadeOutError[Object]

By default the error message will persist on the screen, if you want to fadeout the error enable this option.

timer is in miliseconds.

{
  fadeOutError: {
    fadeOut: true,
    timer: [Number]
  }
}