[Bps-public-commit] rt-extension-formtools branch, enabled-by-select, created. 0.07_07-22-g2640ca8
Thomas Sibley
trs at bestpractical.com
Thu Jun 7 11:01:16 EDT 2012
The branch, enabled-by-select has been created
at 2640ca8bd18d0a7c5db1b0d7b52980fcb987e5cf (commit)
- Log -----------------------------------------------------------------
commit 9ed19e3fbfab85180f236151e5e367c6ae2ed698
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Jun 7 10:56:44 2012 -0400
Allow enabling of fields by a <select>
This includes dropdowns and single or multiple pick boxes.
diff --git a/html/FormTools/Field b/html/FormTools/Field
index 467dec4..5cf64b5 100644
--- a/html/FormTools/Field
+++ b/html/FormTools/Field
@@ -88,7 +88,7 @@ unless ( $default ) {
% }
for ( var i = 0; i<fields.length; i++ ) {
var field = fields[i];
- jQuery('input[name="'+ field +'"], input[name="'+ field +'s"]').change( function(e) {
+ jQuery('*[name="'+ field +'"], *[name="'+ field +'s"]').filter('input,select').change( function(e) {
disable_form_field( should_disable_form_field(fields, values), <% $escape->( $container_selector ) |n %> );
});
}
diff --git a/html/NoAuth/js/form_tools.js b/html/NoAuth/js/form_tools.js
index 6fdc3f8..0e53d5c 100644
--- a/html/NoAuth/js/form_tools.js
+++ b/html/NoAuth/js/form_tools.js
@@ -15,6 +15,8 @@ function should_disable_form_field( fields, values ) {
var field = fields[i];
var selector = 'input[name="'+ field +'"]'
+', input[name="'+ field +'s"]'
+ +', select[name="'+ field +'"]>option'
+ +', select[name="'+ field +'s"]>option'
+', span.readonly[name="'+ field +'"]'
+', li.readonly[name="'+ field +'"]'
;
@@ -25,10 +27,15 @@ function should_disable_form_field( fields, values ) {
var value;
if ( this.tagName == 'SPAN' || this.tagName == 'LI' ) {
value = jQuery(this).text();
- } else if ( this.type == 'radio' || this.type == 'checkbox' ) {
- if ( !jQuery(this).is(':checked') ) return 0;
- value = this.value;
- } else if ( this.type == 'hidden' ) {
+ } else if ( this.tagName == 'INPUT' ) {
+ if ( this.type == 'radio' || this.type == 'checkbox' ) {
+ if ( !jQuery(this).is(':checked') ) return 0;
+ value = this.value;
+ } else if ( this.type == 'hidden' ) {
+ value = this.value;
+ }
+ } else if ( this.tagName == 'OPTION' ) {
+ if ( !jQuery(this).is(':selected') ) return 0;
value = this.value;
}
for ( var i = 0; i < values[field].length; i++ ) {
commit 2640ca8bd18d0a7c5db1b0d7b52980fcb987e5cf
Author: Thomas Sibley <trs at bestpractical.com>
Date: Thu Jun 7 10:58:16 2012 -0400
Disable textareas and generic buttons too
Textareas are just like large <input> fields.
Normal submit and reset buttons were already being disabled by catching
all <input> elements regardless of type, so include <button> elements
as well.
Although this is a behaviour change, hopefully no one was relying on the
this quirk of element selection. If so, they can adjust their
containing elements appropriately.
diff --git a/html/NoAuth/js/form_tools.js b/html/NoAuth/js/form_tools.js
index 0e53d5c..0b35463 100644
--- a/html/NoAuth/js/form_tools.js
+++ b/html/NoAuth/js/form_tools.js
@@ -1,10 +1,10 @@
function disable_form_field(disable, selector) {
if ( disable ) {
- jQuery(selector).addClass('hidden').find('input,select').attr('disabled', 'disabled');
+ jQuery(selector).addClass('hidden').find('input,select,textarea,button').attr('disabled', 'disabled');
}
else {
jQuery(selector).removeClass('hidden');
- jQuery(selector).find('input,select').filter( function() {
+ jQuery(selector).find('input,select,textarea,button').filter( function() {
return jQuery(this).closest('.hidden').length == 0
} ).removeAttr('disabled');
}
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list