2008-09-29 03:18:23 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableEmailField
|
2009-04-17 02:26:40 +00:00
|
|
|
*
|
2008-09-29 03:18:23 +00:00
|
|
|
* Allow users to define a validating editable email field for a UserDefinedForm
|
2009-04-17 02:26:40 +00:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 03:18:23 +00:00
|
|
|
*/
|
2009-12-07 02:04:20 +00:00
|
|
|
|
2008-09-29 03:18:23 +00:00
|
|
|
class EditableEmailField extends EditableFormField {
|
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $singular_name = 'Email Field';
|
2008-09-29 03:18:23 +00:00
|
|
|
|
2013-04-02 18:34:43 -07:00
|
|
|
private static $plural_name = 'Email Fields';
|
2008-09-29 03:18:23 +00:00
|
|
|
|
2014-04-16 11:48:10 +12:00
|
|
|
public function getSetsOwnError() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-04 13:39:08 +12:00
|
|
|
public function getFormField() {
|
2014-12-22 12:19:33 +10:30
|
|
|
|
|
|
|
$field = EmailField::create($this->Name, $this->Title);
|
|
|
|
|
2014-02-12 12:14:42 +13:00
|
|
|
if ($this->Required) {
|
2014-12-22 12:19:33 +10:30
|
|
|
// Required and Email validation can conflict so add the Required validation messages
|
2014-02-12 12:14:42 +13:00
|
|
|
// as input attributes
|
|
|
|
$errorMessage = $this->getErrorMessage()->HTML();
|
2014-12-22 12:19:33 +10:30
|
|
|
$field->setAttribute('data-rule-required', 'true');
|
|
|
|
$field->setAttribute('data-msg-required', $errorMessage);
|
2014-02-12 12:14:42 +13:00
|
|
|
}
|
2015-07-24 14:37:48 +12:00
|
|
|
|
|
|
|
$field->setValue($this->Default);
|
2014-12-22 12:19:33 +10:30
|
|
|
|
|
|
|
return $field;
|
2008-09-29 03:18:23 +00:00
|
|
|
}
|
|
|
|
|
2009-04-21 03:44:13 +00:00
|
|
|
/**
|
|
|
|
* Return the validation information related to this field. This is
|
|
|
|
* interrupted as a JSON object for validate plugin and used in the
|
|
|
|
* PHP.
|
|
|
|
*
|
|
|
|
* @see http://docs.jquery.com/Plugins/Validation/Methods
|
|
|
|
* @return Array
|
|
|
|
*/
|
|
|
|
public function getValidation() {
|
2014-04-16 11:48:10 +12:00
|
|
|
return array_merge(parent::getValidation(), array(
|
2009-04-21 03:44:13 +00:00
|
|
|
'email' => true
|
2014-04-16 11:48:10 +12:00
|
|
|
));
|
2009-04-21 03:44:13 +00:00
|
|
|
}
|
2009-12-07 02:04:20 +00:00
|
|
|
}
|