Source of file OpactiyNumericField.php
Size: 2,200 Bytes - Last Modified: 2021-12-23T10:33:25+00:00
/var/www/docs.ssmods.com/process/src/code/OpactiyNumericField.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 | <?php class OpacityNumericField extends NumericField { public function jsValidation() { $formID = $this->form->FormName(); $error = 'is not a number greater that 0 and less-equals than 1, only numbers between 0 and 1 can be accepted for this field.'; $jsFunc =<<<JS Behaviour.register({ "#$formID": { validateNumericField: function(fieldName) { el = _CURRENT_FORM.elements[fieldName]; if(!el || !el.value) return true; if(!isNaN(el.value)) { return true; } if(el.value > 0 || el.value <= 1) { return true; } else { validationError(el, "'" + el.value + "' $error","validation"); return false; } } } }); JS; Requirements::customScript($jsFunc, 'func_validateNumericField'); //return "\$('$formID').validateNumericField('$this->name');"; return <<<JS if(typeof fromAnOnBlur != 'undefined'){ if(fromAnOnBlur.name == '$this->name') $('$formID').validateNumericField('$this->name'); }else{ $('$formID').validateNumericField('$this->name'); } JS; } /** PHP Validation **/ public function validate($validator) { if ($this->value && !is_numeric(trim($this->value))) { $validator->validationError( $this->name, sprintf( "'%s' is not a number greater that 0 and less-equals than 1, only numbers can be accepted for this field.", $this->value ), "validation" ); return false; } if ($this->value >= 0 && $this->value <= 1) { return true; } else { $validator->validationError( $this->name, sprintf( "'%s' is not a number greater that 0 and less-equals than 1, only numbers can be accepted for this field.", $this->value ), "validation" ); return false; } } public function dataValue() { return (is_numeric($this->value) && $this->value <= 1 && $this->value >= 0) ? $this->value : 0; } } |