From db2ee67799f0931f662af5bebcd4869082c20f95 Mon Sep 17 00:00:00 2001 From: Thomas Fuchs Date: Tue, 27 Mar 2007 17:53:52 +0000 Subject: [PATCH] Fix Form.disable to work again on non-form elements. Closes #6887. [Mislav Marohnic] --- CHANGELOG | 2 ++ src/form.js | 9 ++------- test/unit/form.html | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cbf2a5b..3691cfc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fix Form.disable to work again on non-form elements. Closes #6887. [Mislav Marohnić] + * Fix an issue with String.prototype.endsWith. Closes #7822. [altblue] *1.5.1_rc2* (March 12, 2007) diff --git a/src/form.js b/src/form.js index 125f95a..06d7ed7 100644 --- a/src/form.js +++ b/src/form.js @@ -56,18 +56,13 @@ Form.Methods = { disable: function(form) { form = $(form); - form.getElements().each(function(element) { - element.blur(); - element.disabled = 'true'; - }); + Form.getElements(form).invoke('disable'); return form; }, enable: function(form) { form = $(form); - form.getElements().each(function(element) { - element.disabled = ''; - }); + Form.getElements(form).invoke('enable'); return form; }, diff --git a/test/unit/form.html b/test/unit/form.html index e58afca..9f81258 100644 --- a/test/unit/form.html +++ b/test/unit/form.html @@ -184,6 +184,37 @@ }); }}, + testFormEnabling: function(){ with(this) { + var form = $('form_focus') + var input1 = form.focus_disabled + var input2 = form.focus_text + + assert(input1.disabled) + assert(!input2.disabled) + + form.disable() + assert(input1.disabled) + assert(input2.disabled) + + form.enable() + assert(!input1.disabled) + assert(!input2.disabled) + + input1.disable() + assert(input1.disabled) + + // non-form elements: + var fieldset = $('form_fieldset') + var fields = fieldset.immediateDescendants() + assert(fields.all(function(select){ return !select.disabled })) + + Form.disable(fieldset) + assert(fields.all(function(select){ return select.disabled })) + + Form.enable(fieldset) + assert(fields.all(function(select){ return !select.disabled })) + }}, + testFormElementEnabling: function(){ with(this) { assert($('input_disabled').disabled); $('input_disabled').enable();