2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableEmailField
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
2008-09-29 05:18:23 +02:00
|
|
|
* Allow users to define a validating editable email field for a UserDefinedForm
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2009-12-07 03:04:20 +01:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
class EditableEmailField extends EditableFormField {
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $singular_name = 'Email Field';
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2013-04-03 03:34:43 +02:00
|
|
|
private static $plural_name = 'Email Fields';
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2015-12-11 02:50:12 +01:00
|
|
|
private static $db = array(
|
|
|
|
'Placeholder' => 'Varchar(255)'
|
|
|
|
);
|
|
|
|
|
|
|
|
public function getCMSFields() {
|
|
|
|
$this->beforeUpdateCMSFields(function($fields) {
|
|
|
|
$fields->addFieldToTab(
|
|
|
|
'Root.Main',
|
|
|
|
TextField::create(
|
|
|
|
'Placeholder',
|
|
|
|
_t('EditableTextField.PLACEHOLDER', 'Placeholder')
|
|
|
|
)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return parent::getCMSFields();
|
|
|
|
}
|
|
|
|
|
2014-04-16 01:48:10 +02:00
|
|
|
public function getSetsOwnError() {
|
|
|
|
return true;
|
|
|
|
}
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2012-05-04 03:39:08 +02:00
|
|
|
public function getFormField() {
|
2015-08-21 05:21:33 +02:00
|
|
|
$field = EmailField::create($this->Name, $this->EscapedTitle, $this->Default)
|
|
|
|
->setFieldHolderTemplate('UserFormsField_holder')
|
|
|
|
->setTemplate('UserFormsField');
|
|
|
|
|
2015-08-10 07:03:36 +02:00
|
|
|
$this->doUpdateFormField($field);
|
2015-08-21 05:21:33 +02:00
|
|
|
|
2014-12-22 02:49:33 +01:00
|
|
|
return $field;
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
2015-09-11 00:20:06 +02:00
|
|
|
|
2009-04-21 05:44:13 +02:00
|
|
|
/**
|
2015-08-11 01:40:37 +02:00
|
|
|
* Updates a formfield with the additional metadata specified by this field
|
2009-04-21 05:44:13 +02:00
|
|
|
*
|
2015-08-11 01:40:37 +02:00
|
|
|
* @param FormField $field
|
2009-04-21 05:44:13 +02:00
|
|
|
*/
|
2015-08-11 01:40:37 +02:00
|
|
|
protected function updateFormField($field) {
|
|
|
|
parent::updateFormField($field);
|
|
|
|
|
|
|
|
$field->setAttribute('data-rule-email', true);
|
2015-12-11 02:50:12 +01:00
|
|
|
|
|
|
|
if($this->Placeholder) {
|
|
|
|
$field->setAttribute('placeholder', $this->Placeholder);
|
|
|
|
}
|
2009-04-21 05:44:13 +02:00
|
|
|
}
|
2009-12-07 03:04:20 +01:00
|
|
|
}
|