silverstripe-userforms/code/model/formfields/EditableNumericField.php
Damian Mooyman 5e0b7fdf7a Updated jquery validate plugin (dist files only)
Cleanup of validation script. Refactor into template to allow customisation of validation.
Explicitly set error element to 'span' as per new jquery-validate support
[ref: CWPBUG-110]
2014-05-22 10:34:11 +12:00

44 lines
1.1 KiB
PHP
Executable File

<?php
/**
* EditableNumericField
*
* This control represents a user-defined numeric field in a user defined form
*
* @package userforms
*/
class EditableNumericField extends EditableTextField {
private static $singular_name = 'Numeric Field';
private static $plural_name = 'Numeric Fields';
public function getSetsOwnError() {
return true;
}
/**
* @return TextareaField|TextField
*/
public function getFormField() {
if($this->getSetting('Rows') && $this->getSetting('Rows') > 1) {
$taf = new NumericField($this->Name, $this->Title);
$taf->setRows($this->getSetting('Rows'));
$taf->addExtraClass('number');
}
else {
$taf = new NumericField($this->Name, $this->Title, null, $this->getSetting('MaxLength'));
$taf->addExtraClass('number');
}
if ($this->Required) {
// Required and numeric validation can conflict so add the Required validation messages
// as input attributes
$errorMessage = $this->getErrorMessage()->HTML();
$taf->setAttribute('data-rule-required','true');
$taf->setAttribute('data-msg-required',$errorMessage);
}
return $taf;
}
}