Add number validators see #8177

pull/2487/head
jmontoyaa 9 years ago
parent b879482f49
commit d302357111
  1. 2
      main/exercice/exercise.class.php
  2. 30
      main/inc/lib/pear/HTML/QuickForm/Rule/Range.php
  3. 5
      main/inc/lib/pear/HTML/QuickForm/RuleRegistry.php

@ -2243,6 +2243,8 @@ class Exercise
array('id' => 'pass_percentage')
);
$form->addRule('pass_percentage', get_lang('Numeric'), 'numeric');
$form->addRule('pass_percentage', get_lang('ValueTooSmall'), 'min_numeric_length', 0);
$form->addRule('pass_percentage', get_lang('ValueTooBig'), 'max_numeric_length', 100);
// add the text_when_finished textbox
$form->addHtmlEditor(

@ -40,21 +40,25 @@ class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
* @access public
* @return boolean true if value is valid
*/
function validate($value, $options)
public function validate($value, $options)
{
// Modified by Ivan Tcholakov, 16-MAR-2010.
//$length = strlen($value);
$length = api_strlen($value);
//
switch ($this->name) {
case 'minlength': return ($length >= $options);
case 'maxlength': return ($length <= $options);
default: return ($length >= $options[0] && $length <= $options[1]);
case 'min_numeric_length':
return (float) $value >= $options;
case 'max_numeric_length':
return (float) $value <= $options;
case 'minlength':
return $length >= $options;
case 'maxlength':
return $length <= $options;
default:
return $length >= $options[0] && $length <= $options[1];
}
} // end func validate
}
function getValidationScript($options = null)
public function getValidationScript($options = null)
{
switch ($this->name) {
case 'minlength':
@ -67,7 +71,5 @@ class HTML_QuickForm_Rule_Range extends HTML_QuickForm_Rule
$test = '({jsVar}.length < '.$options[0].' || {jsVar}.length > '.$options[1].')';
}
return array('', "{jsVar} != '' && {$test}");
} // end func getValidationScript
} // end class HTML_QuickForm_Rule_Range
?>
}
}

@ -119,6 +119,8 @@ class HTML_QuickForm_RuleRegistry
'required' => 'HTML_QuickForm_Rule_Required',
'maxlength' => 'HTML_QuickForm_Rule_Range',
'minlength' => 'HTML_QuickForm_Rule_Range',
'max_numeric_length' => 'HTML_QuickForm_Rule_Range',
'min_numeric_length' => 'HTML_QuickForm_Rule_Range',
'rangelength' => 'HTML_QuickForm_Rule_Range',
'email' => 'HTML_QuickForm_Rule_Email',
'regex' => 'HTML_QuickForm_Rule_Regex',
@ -149,8 +151,7 @@ class HTML_QuickForm_RuleRegistry
'maxfilesize', 'HTML_QuickForm_Rule_MaxFileSize',
'mimetype', 'HTML_QuickForm_Rule_MimeType',
'filename', 'HTML_QuickForm_Rule_FileName',
'validquestiontype' => 'HTML_QuickForm_Rule_QuestionType',
'validquestiontype' => 'HTML_QuickForm_Rule_QuestionType'
);
$class = $rules[$ruleName];

Loading…
Cancel
Save