r89597 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89596‎ | r89597 | r89598 >
Date:19:45, 6 June 2011
Author:salvatoreingala
Status:deferred
Tags:
Comment:
- Bugfix in client side validation in presence of not-"required" fields
- Using newer PHP syntax, per r89584#c17673
Modified paths:
  • /branches/salvatoreingala/Gadgets/Gadgets_body.php (modified) (history)
  • /branches/salvatoreingala/Gadgets/modules/jquery.formBuilder.js (modified) (history)

Diff [purge]

Index: branches/salvatoreingala/Gadgets/Gadgets_body.php
@@ -266,7 +266,7 @@
267267 'number' => array(
268268 'default' => array(
269269 'isMandatory' => true,
270 - 'checker' => array( 'Gadget', 'isFloatOrInt' )
 270+ 'checker' => 'Gadget::isFloatOrInt'
271271 ),
272272 'label' => array(
273273 'isMandatory' => true,
@@ -282,19 +282,19 @@
283283 ),
284284 'min' => array(
285285 'isMandatory' => false,
286 - 'checker' => array( 'Gadget', 'isFloatOrInt' )
 286+ 'checker' => 'Gadget::isFloatOrInt'
287287 ),
288288 'max' => array(
289289 'isMandatory' => false,
290 - 'checker' => array( 'Gadget', 'isFloatOrInt' )
 290+ 'checker' => 'Gadget::isFloatOrInt'
291291 )
292292 )
293293 );
294294
295295 //Type-specific checkers for finer validation
296296 private static $typeCheckers = array(
297 - 'string' => array( 'Gadget', 'checkStringOption' ),
298 - 'number' => array( 'Gadget', 'checkNumberOption' )
 297+ 'string' => 'Gadget::checkStringOption',
 298+ 'number' => 'Gadget::checkNumberOption'
299299 );
300300
301301 //Further checks for 'string' options
@@ -724,10 +724,9 @@
725725 if ( !isset( self::$prefsDescriptionSpecifications[$type] ) ) {
726726 return false;
727727 }
728 -
 728+
729729 //TODO: check $option name compliance
730730
731 -
732731 //Check if all fields satisfy specification
733732 $typeSpec = self::$prefsDescriptionSpecifications[$type];
734733 $count = 0; //count of present mandatory members
Index: branches/salvatoreingala/Gadgets/modules/jquery.formBuilder.js
@@ -18,6 +18,16 @@
1919 }
2020
2121
 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+
2232 //validator for "required" fields (without trimming whitespaces)
2333 $.validator.addMethod( "requiredStrict", function( value, element ) {
2434 return value.length > 0;
@@ -25,17 +35,17 @@
2636
2737 //validator for "minlength" fields (without trimming whitespaces)
2838 $.validator.addMethod( "minlengthStrict", function( value, element, param ) {
29 - return value.length >= param;
 39+ return testOptional( value, element ) || value.length >= param;
3040 } );
3141
3242 //validator for "maxlength" fields (without trimming whitespaces)
3343 $.validator.addMethod( "maxlengthStrict", function( value, element, param ) {
34 - return value.length <= param;
 44+ return testOptional( value, element ) || value.length <= param;
3545 } );
3646
3747 //validator for integer fields
3848 $.validator.addMethod( "integer", function( value, element ) {
39 - return this.optional( element ) || /^-?\d+$/.test(value);
 49+ return testOptional( value, element ) || /^-?\d+$/.test(value);
4050 }, mw.msg( 'gadgets-formbuilder-integer' ) );
4151
4252

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89584- Added preferences of type "number"...salvatoreingala17:37, 6 June 2011

Status & tagging log