Commit 2277666c authored by jaapjansma's avatar jaapjansma

Added min/max validators

parent 34119dd7
......@@ -4,6 +4,7 @@ Version 1.7 (not yet released)
* Fixed #9 Error in the default value
* Fixed #11 Errors in DateType validation
* Added try out functionality.
* Added Min/Max validators.
Version 1.6
===========
......
......@@ -27,6 +27,8 @@
private function __construct() {
$this->addValidator(new EmailValidator());
$this->addValidator(new MinLengthValidator());
$this->addValidator(new MinValidator());
$this->addValidator(new MaxValidator());
}
/**
......
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
namespace Civi\FormProcessor\Validation;
use Civi\FormProcessor\Config\Specification;
use Civi\FormProcessor\Config\SpecificationBag;
use CRM_FormProcessor_ExtensionUtil as E;
class MaxValidator extends AbstractValidator {
public function getLabel() {
return E::ts('Is less than or equal to');
}
/** Returns the invalid message.
*
* @return string
*/
public function getInvalidMessage() {
return E::ts('Value can not be greater than %1', [1=>$this->configuration->get('max_value')]);
}
/**
* Returns the name of the validator.
*
* @return string
*/
public function getName() {
return 'max';
}
/**
* Validate the input.
*
* @param mixed $input
* @return bool
*/
public function validate($input) {
return $input <= $this->configuration->get('max_value') ? true : false;
}
/**
* Get the configuration specification
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new Specification('max_value', 'Integer', E::ts('Maximum value'), true)
));
}
}
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
namespace Civi\FormProcessor\Validation;
use Civi\FormProcessor\Config\Specification;
use Civi\FormProcessor\Config\SpecificationBag;
use CRM_FormProcessor_ExtensionUtil as E;
class MinValidator extends AbstractValidator {
public function getLabel() {
return E::ts('Is greater than or equal to');
}
/**
* Returns the name of the validator.
*
* @return string
*/
public function getName() {
return 'min';
}
/** Returns the invalid message.
*
* @return string
*/
public function getInvalidMessage() {
return E::ts('Value can not be less than %1', [1=>$this->configuration->get('min_value')]);
}
/**
* Validate the input.
*
* @param mixed $input
* @return bool
*/
public function validate($input) {
return $input >= $this->configuration->get('min_value') ? true : false;
}
/**
* Get the configuration specification
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new Specification('min_value', 'Integer', E::ts('Minimum value'), true)
));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment