Code Monkey home page Code Monkey logo

postform's Introduction

Postform

Install

$ npm install postform --save

Usage

var Postform = require('postform');
new Postform({
            form: '#form-id'
        }).after('submit', function(res) {
           console.log(res);
        });

chang post data before submit


new Postform({
        form: '#form'
    }).after('getdata',function(data){
        data.append='hello';
    }).after('submit', function (res) {
        if (res.result === true) {
            alert('提交成功');
        } else {
            this.errors(res);
        }
    });
    

extend

use bootstrap3 show errors

var $ = require("jquery");
var Postform = require("postform");
Postform.implement({
        errors: function(res) {
            var self = this;

            self.$form.find('.has-error').removeClass('has-error').find('.help-block').html('');
            self.$form.find('.ui-form-explain').html('');
            $.each(res.msgs, function(field_name, field_msg) {
                self.$form.find('input[name=' + field_name + '],select[name=' + field_name + '],textarea[name=' + field_name + ']')
                        .parents('.form-group:first')
                        .addClass('has-error')
                        .find('.help-block')
                        .html('<i class="iconfont">&#xf0155;</i>' + field_msg);
            });
        }
});

 module.exports = Postform;

postform's People

Contributors

minuux avatar

Watchers

 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.