Parsley.js Documentation

repository·master·Indexed 27 days ago

https://github.com/guillaumepotier/parsley.js

A powerful JavaScript form validation library (version 2.9.2) that enables developers to implement complex validation logic using HTML5 attributes, minimizing the need for manual JavaScript coding. Requires jQuery >= 1.8 and es5-shim for Internet Explorer 8 support.

Tokens
5.3K
Snippets
24
Records
49
Agent score
94%

What's inside Parsley.js

  1. Overview of Parsley.js

    master

    Parsley.js is a JavaScript form validation library that allows you to perform validation without writing custom JavaScript code, primarily through HTML5 attributes.

    Maintenance Status: The project is considered stable. No new features are planned, and maintenance is minimal, focusing on bug fixes.

  2. Understand Bootstrap package structure

    master

    The Bootstrap download includes logically grouped assets, providing both compiled and minified variations:

    • css/: Contains bootstrap.css, bootstrap.min.css, and optional theme files (bootstrap-theme.css, bootstrap-theme.min.css).
    • js/: Contains bootstrap.js and bootstrap.min.js.
    • fonts/: Includes Glyphicons font files (.eot, .svg, .ttf, .woff).
  3. Migrate from Parsley 2.1.x to 2.2.0+

    master

    When upgrading from version 2.1.x to 2.2.0 or higher, note the following architectural changes:

    1. Unified Version: The remote and basic versions of Parsley have been merged into a single version that is both remote and promise-aware. This version is lighter than the previous 2.1.x iterations.
    2. ES6 Source: The Parsley source code is now written in ECMAScript 6.
    3. i18n Location: The i18n folder is now located within the dist folder.
    4. Deprecation Notices: Check your browser console for deprecation notices to identify and adapt code that may become incompatible in future versions.
  4. Install and initialize the Universal Widget

    master

    The Universal Widget is a simple jQuery plugin used to display collections of objects from a remote API with built-in sorting, filtering, and direction controls.

    Requirements:

    • jQuery >= 1.6
    • Include the gh-issues-widget.css stylesheet.

    To use it, create a div with the class uwidget and initialize it using the .UWidget() method within a jQuery $(document).ready() block.

    <html>
    <head>
    <link href="gh-issues-widget.css" rel="stylesheet">
    </head>
    <body>
      <div class="uwidget" data-width="500px" data-height="300px"></div>
      <script type="text/javascript">
        $(document).ready(function () {
          $('.uwidget').UWidget({
            url: 'https://api.url.ext',
            handler: function (data) {
              // special remote data treatment needed ?
              return data;
            },
            template: 'item_tmpl',
            sort: {
              enabled: true,
              name: 'sort',
              values: ['created', 'updated', 'comments'],
              labels: ['Creation date', 'Update date', 'Comments']
            },
            direction: {
              enabled: true,
              name: 'direction',
              values: ['desc', 'asc'],
              labels: ['Descending', 'Ascending']
            },
            filters: {
              enabled: true,
              name: 'labels',
              values: ['bug', 'enhancement'],
              labels: ['Bug', 'Enhancement']
            }
          });
        });
      </script>
      <script type="text/html" id="item_tmpl">
        <li>
          <span class="gh-issue-comments">
            <%= comments %> <%= comments > 1 ? "comments" : "commment" %>
          </span>
          <span class="gh-issue-title">
            <a href="<%= html_url %>"><%= title %></a>
          </span>
        </li>
      </script>
    </body>
    </html>
  5. Integrate expect.js with Mocha

    master

    Expect.js is compatible with all test frameworks. When an expectation fails, it raises an exception that test runners like Mocha capture and report.

    describe('test suite', function () {
      it('should expose a function', function () {
        expect(add).to.be.a('function');
      });
    
      it('should do math', function () {
        expect(add(1, 3)).to.equal(4);
      });
    });
  6. Migrate from Parsley 1.x to 2.0: UI/UX and CSS Classes

    master

    UI behaviors and CSS classes have been updated in version 2.0:

    • Validation State: The .parsley-validated class is no longer added to bound fields.
    • Form Attributes: The novalidate attribute is now automatically added to <form> elements.
    • Error List Class: The class .parsley-error-list has been renamed to .parsley-errors-list.
    • Customizing Type Error Messages: You no longer need to specify the precise type in the attribute name. For example, change data-parsley-type-email-message="msg" to data-parsley-type-message="msg".
  7. Migrate from Parsley 1.x to 2.0: Validators

    master

    Several validator names and behaviors have changed in version 2.0:

    • required: Now accepts a false value to become inactive.
    • length: Renamed from rangelength (requirements remain the same).
    • check: Renamed from rangecheck (requirements remain the same).
    • Removed Validators: notnull, type="urlstrict", and type="tel" are no longer built-in. Additionally, the types phone, urlstrict, and dateIso have been removed and must be implemented via extra validators.
  8. Migrate from Parsley 1.x to 2.0: Remote Validator and Extensions

    master

    In version 2.0, the remote validator is no longer part of the core bundle; it is now shipped in parsley.remote.js.

    Additionally, parsley.extend has been removed. Extra validators are now organized in a directory and can be compiled into a single file using a build script.