This site contains the document for old version. Please upgrade to the latest version v1.0.0

Integrating with Rails

Examples

For Rails, the input field is constructed from model name and field name. For example, user have email as field, when form helper render view, the input field name will be 'user[email]'. The syntax for calling the plugin looks like below:

$(form).formValidation({
    framework: 'bootstrap',
    fields: {
        'user[email]': {
            validatorName: validatorOptions
        }
    }
});

When using FormValidation in a Rails remote form, in order to prevent the form from multiple submissions, trigger the success.form.fv event as following:

$(form)
    .formValidation({
        ...
    })
    .on('success.form.fv', function(e) {
        // Called when the form is valid
        var $form = $(e.target);
        if ($form.data('remote')) {
            e.preventDefault();
            return false;
        }
    })
    .on('submit', function(e) {
        var $form = $(e.target);
        if ($form.data('remote')) {
            var numInvalidFields = $form.data('formValidation').getInvalidFields().length;
            if (numInvalidFields) {
                e.preventDefault();
                return false;
            }
        }
    });

Resources