Index: branches/salvatoreingala/Gadgets/Gadgets_body.php |
— | — | @@ -266,7 +266,7 @@ |
267 | 267 | 'number' => array( |
268 | 268 | 'default' => array( |
269 | 269 | 'isMandatory' => true, |
270 | | - 'checker' => array( 'Gadget', 'isFloatOrInt' ) |
| 270 | + 'checker' => 'Gadget::isFloatOrInt' |
271 | 271 | ), |
272 | 272 | 'label' => array( |
273 | 273 | 'isMandatory' => true, |
— | — | @@ -282,19 +282,19 @@ |
283 | 283 | ), |
284 | 284 | 'min' => array( |
285 | 285 | 'isMandatory' => false, |
286 | | - 'checker' => array( 'Gadget', 'isFloatOrInt' ) |
| 286 | + 'checker' => 'Gadget::isFloatOrInt' |
287 | 287 | ), |
288 | 288 | 'max' => array( |
289 | 289 | 'isMandatory' => false, |
290 | | - 'checker' => array( 'Gadget', 'isFloatOrInt' ) |
| 290 | + 'checker' => 'Gadget::isFloatOrInt' |
291 | 291 | ) |
292 | 292 | ) |
293 | 293 | ); |
294 | 294 | |
295 | 295 | //Type-specific checkers for finer validation |
296 | 296 | private static $typeCheckers = array( |
297 | | - 'string' => array( 'Gadget', 'checkStringOption' ), |
298 | | - 'number' => array( 'Gadget', 'checkNumberOption' ) |
| 297 | + 'string' => 'Gadget::checkStringOption', |
| 298 | + 'number' => 'Gadget::checkNumberOption' |
299 | 299 | ); |
300 | 300 | |
301 | 301 | //Further checks for 'string' options |
— | — | @@ -724,10 +724,9 @@ |
725 | 725 | if ( !isset( self::$prefsDescriptionSpecifications[$type] ) ) { |
726 | 726 | return false; |
727 | 727 | } |
728 | | - |
| 728 | + |
729 | 729 | //TODO: check $option name compliance |
730 | 730 | |
731 | | - |
732 | 731 | //Check if all fields satisfy specification |
733 | 732 | $typeSpec = self::$prefsDescriptionSpecifications[$type]; |
734 | 733 | $count = 0; //count of present mandatory members |
Index: branches/salvatoreingala/Gadgets/modules/jquery.formBuilder.js |
— | — | @@ -18,6 +18,16 @@ |
19 | 19 | } |
20 | 20 | |
21 | 21 | |
| 22 | + function testOptional( value, element ) { |
| 23 | + var rules = $( element ).rules(); |
| 24 | + if ( typeof rules.required == 'undefined' || rules.required === false ) { |
| 25 | + if ( value.length == 0 ) { |
| 26 | + return true; |
| 27 | + } |
| 28 | + } |
| 29 | + return false; |
| 30 | + } |
| 31 | + |
22 | 32 | //validator for "required" fields (without trimming whitespaces) |
23 | 33 | $.validator.addMethod( "requiredStrict", function( value, element ) { |
24 | 34 | return value.length > 0; |
— | — | @@ -25,17 +35,17 @@ |
26 | 36 | |
27 | 37 | //validator for "minlength" fields (without trimming whitespaces) |
28 | 38 | $.validator.addMethod( "minlengthStrict", function( value, element, param ) { |
29 | | - return value.length >= param; |
| 39 | + return testOptional( value, element ) || value.length >= param; |
30 | 40 | } ); |
31 | 41 | |
32 | 42 | //validator for "maxlength" fields (without trimming whitespaces) |
33 | 43 | $.validator.addMethod( "maxlengthStrict", function( value, element, param ) { |
34 | | - return value.length <= param; |
| 44 | + return testOptional( value, element ) || value.length <= param; |
35 | 45 | } ); |
36 | 46 | |
37 | 47 | //validator for integer fields |
38 | 48 | $.validator.addMethod( "integer", function( value, element ) { |
39 | | - return this.optional( element ) || /^-?\d+$/.test(value); |
| 49 | + return testOptional( value, element ) || /^-?\d+$/.test(value); |
40 | 50 | }, mw.msg( 'gadgets-formbuilder-integer' ) ); |
41 | 51 | |
42 | 52 | |