jrobinsonc
8/29/2012 - 3:48 PM

jQuery: Disable form #forms #jquery #javascript

jQuery: Disable form #forms #jquery #javascript

/*global jQuery*/

jQuery(function ($) {

    'use strict';

    $('form').bind('disable-form', function () {

        $(this).find(':input')
            .not(':disabled')
            .removeClass('disabled-form-input')
            .addClass('disabled-form-input')
            .prop('disabled', true);

    }).bind('enable-form', function () {

        $(this).find('.disabled-form-input')
            .removeClass('disabled-form-input')
            .prop('disabled', false);

    });

});

Disable Forms

Introduction

Disable the fields of forms. This does not touch the fields that are disabled at the moment of disabling. This script is executed like an event call.

This depends of jQuery.

Usage

Disable form:

$('#form1').trigger('disable-form');

Enable form:

$('#form1').trigger('enable-form');