| @@ 19-47 (lines=29) @@ | ||
| 16 | * @version 1.0 |
|
| 17 | * @since 1.0 |
|
| 18 | */ |
|
| 19 | class NumberValidator extends BaseValidator |
|
| 20 | { |
|
| 21 | /** |
|
| 22 | * @inheritdoc |
|
| 23 | */ |
|
| 24 | public function validate(IFormModel $model) |
|
| 25 | { |
|
| 26 | foreach ($this->elements AS $element) { |
|
| 27 | if (!$model->checkAttributeExists($element)) { |
|
| 28 | $this->errors[] = 'Parameter '.$element.' not defined in class '.get_class($model); |
|
| 29 | ||
| 30 | return false; |
|
| 31 | } |
|
| 32 | if (!is_numeric($model->$element)) { |
|
| 33 | $this->errors[] = 'Parameter '.$element.' is not a numeric'; |
|
| 34 | } |
|
| 35 | } |
|
| 36 | ||
| 37 | return true; |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @inheritdoc |
|
| 42 | */ |
|
| 43 | public function client(IFormModel $model) |
|
| 44 | { |
|
| 45 | return 'if (! ((this.value ^ 0) === this.value) ) { e.preventDefault(); this.focus(); alert(\'Value is not number\'); }'; |
|
| 46 | } |
|
| 47 | } |
|
| 48 | ||
| @@ 19-49 (lines=31) @@ | ||
| 16 | * @version 1.0 |
|
| 17 | * @since 1.0 |
|
| 18 | */ |
|
| 19 | class RequiredValidator extends BaseValidator |
|
| 20 | { |
|
| 21 | /** |
|
| 22 | * @inheritdoc |
|
| 23 | */ |
|
| 24 | public function validate(IFormModel $model) |
|
| 25 | { |
|
| 26 | foreach ($this->elements AS $element) { |
|
| 27 | if (!$model->checkAttributeExists($element)) { |
|
| 28 | $this->errors[] = 'Parameter '.$element.' not defined in class '.get_class($model); |
|
| 29 | ||
| 30 | return false; |
|
| 31 | } |
|
| 32 | if (!$model->$element) { |
|
| 33 | $this->errors[] = $element.' error: required element is empty.'; |
|
| 34 | ||
| 35 | return false; |
|
| 36 | } |
|
| 37 | } |
|
| 38 | ||
| 39 | return true; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @inheritdoc |
|
| 44 | */ |
|
| 45 | public function client(IFormModel $model) |
|
| 46 | { |
|
| 47 | return 'if (!this.value) { e.preventDefault(); this.focus(); alert(\'Required element!\'); }'; |
|
| 48 | } |
|
| 49 | } |
|
| 50 | ||