viverae / marionette.formview

Marionette Form View, Easy Form Validation, Serialization and Submission
76 stars 16 forks source link

Marionette.Formview Build Status Bitdeli Badge

A Flexible and customizable Backbone.Marionette Form View.

Getting Started

This is a plugin built on top of the base Marionette ItemView.

Basic knowledge of Backbone(http://backbonejs.org/) and Backbone.Marionette(http://marionettejs.com/) is recommended

Quick JSFiddle Example : http://jsfiddle.net/hxvXL/10/

var LoginFormView = Marionette.FormView.extend({

    el: '#formContainer',

    //define form fields
    fields: {
        email: {
            el: ".email",
            required: "Please enter a valid Email Address.",
            validations: {
                email: "Please enter a valid Email Address."
            }
        },
        password: {
            el: ".password",
            required: "Please enter your password.",
            validations: {
                password: "Please enter a valid Password."
            }
        }
    },

    //custom validation rules
    rules: {
        password: function(val) {
            return /^['a-zA-Z]+$/.test(val);
        }
    },

    //handle successful submissions
    onSubmit: function(evt) {
        evt.preventDefault();
    },

    //handle validation failures
    onSubmitFail: function(errors) {

    }
});

Dependencies

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Release History

License

Copyright (c) 2012-2014 OneHealth Solutions, Inc

Copyright (c) 2014-2015 Viverae, Inc

Licensed under the Apache 2.0 license.

Author

Chris Miller