Giter VIP home page Giter VIP logo

brightspot-js-form's Introduction

bsp-form

Introduction

Provides utlities and plugins to build an alternate, highly flexible user interface for HTML forms inside Brightspot CMS.

  • Replaces the native form validation user interface, but still uses native HTML5 constraint validation to validate fields
  • Can revert to native UI if needed
  • Can use native browser validation messages or custom messages
  • Adds helper classes on the form and field elements to aid styling
  • Allows outputting field messages anywhere on the page
  • Custom field constraints can be written with very little code and shared among multiple projects.

Install

bower install --save perfectsense/brightspot-js-form

Then load modules into your project as seen in Brightspot Base.

Usage

Enabling

To enable, add a data-bsp-form attribute to a form element.

Validation Messages

You can output the form validation message from a specific field into any element on the page using the data-bsp-form-message attribute. This example displays the validation messages from a field with the id "myfield":

<div data-bsp-form-message="#myfield"></div>

@todo: document options

Custom Field Constraints

Custom field contraints are added to a field with a data attribute like this:

<label>My field <input type="text" name="myfield" id="myfield" title="My field"
required bsp-form-constraint-myfield /></label>

Then you can create a new constraint by extending the base constraint object.

See: a simple synchronous example, a simple asynchronous example, and a more complex reusable constraint.

The above contraint objects are all imported into plugins like this one and instantiated there.

Custom contraints are not evaluated until all native contraints on a field pass. In the above example, the custom contraint would not run if the user had not entered any text yet because of the "required" attribute.

@todo document options

@todo document object properties/methods

Custom Classes

bsp-form adds several classes to the form and its fields. These classes can be combined with native :valid, :invalid, and :required pseudo selectors to conditionally display formatting/messages.

  • clean/dirty - When the form is clean, no fields have been edited. If a single field has been edited, the field and the form lose the clean class and gain the dirty class. Other fields will keep the clean class until a edited.
  • submitted - Added to the form element after submitting the form, removed if the form is reset.

Demo

You have to run through http, so an express server is provided.

Run node demo/server.js from the project root.

Visit http://localhost:3000 in a browser.

brightspot-js-form's People

Contributors

jpencola avatar rustytanton avatar rustytanton-zz avatar trhoppe avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.