Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active October 9, 2015 13:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrobinsonc/3514694 to your computer and use it in GitHub Desktop.
Save jrobinsonc/3514694 to your computer and use it in GitHub Desktop.
jQuery: Disable form #forms #jquery #javascript

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');
/*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);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment