5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 855 Views |
-
NumericField with specific input range validate

10 April 2011 at 10:22am
I have a NumericField that represents the amount of items in a video page.
In the CMS i have a NumericField that may only contain a number between 1 and infinity. How can i make a validator on the NumericField so that is doesn't allow negative numbers or a zero?Any help will be welcome!
-
Re: NumericField with specific input range validate

11 April 2011 at 11:03pm Last edited: 11 April 2011 11:03pm
note this is code I use in ModelAdmin, so it may require changing to work for a Page...
in the MyPage.php
...
function getCMSValidator() {
return new MyValidator();
}
...
}...
class MyValidator extends RequiredFields {
function php($data) {
$bRet = parent::php($data);$i = (int)$data['ItemsInAVideoPage'];
if (!ctype_digit($strValue) || $i < 1) {
$this->validationError('ItemsInAVideoPage','Items In A Video Page must be a non-zero integer',"required");
$bRet = false;
}return $bRet;
}
}
| 855 Views | ||
|
Page:
1
|
Go to Top |


