2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* EditableDateField
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
2008-09-29 05:18:23 +02:00
|
|
|
* Allows a user to add a date field to the Field Editor
|
2009-04-17 04:26:40 +02:00
|
|
|
*
|
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
|
|
|
class EditableDateField extends EditableFormField {
|
2009-04-21 05:44:13 +02:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
static $singular_name = 'Date field';
|
2009-04-21 05:44:13 +02:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
static $plural_name = 'Date fields';
|
|
|
|
|
2009-04-17 04:26:40 +02:00
|
|
|
function populateFromPostData($data) {
|
2008-09-29 05:18:23 +02:00
|
|
|
$fieldPrefix = 'Default-';
|
|
|
|
|
|
|
|
if( empty( $data['Default'] ) && !empty( $data[$fieldPrefix.'Year'] ) && !empty( $data[$fieldPrefix.'Month'] ) && !empty( $data[$fieldPrefix.'Day'] ) )
|
|
|
|
$data['Default'] = $data['Year'] . '-' . $data['Month'] . '-' . $data['Day'];
|
|
|
|
|
|
|
|
// Debug::show( $data );
|
|
|
|
|
|
|
|
parent::populateFromPostData( $data );
|
|
|
|
}
|
|
|
|
|
2009-04-21 05:44:13 +02:00
|
|
|
/**
|
|
|
|
* Return the form field.
|
|
|
|
*
|
|
|
|
* @todo Make a jQuery safe form field. The current CalendarDropDown
|
|
|
|
* breaks on the front end.
|
|
|
|
*/
|
|
|
|
public function getFormField() {
|
|
|
|
return new TextField( $this->Name, $this->Title, $this->Default);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
|
|
|
return array(
|
|
|
|
'date' => true
|
|
|
|
);
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|