MDL-5583 mod_data: Add required fields
This is implemented for most fields but not all. The reason is that there are
some fields for which this does not make sense because no entry is a valid entry.
The supported fields are:
checkbox
file
latlong
menu
number
picture
radio
text
textarea
url
The unsupported fields are:
date
multimenu
This commit is contained in:
@@ -34,16 +34,29 @@ class data_field_date extends data_field_base {
|
||||
var $month = 0;
|
||||
var $year = 0;
|
||||
|
||||
function display_add_field($recordid=0) {
|
||||
function display_add_field($recordid = 0, $formdata = null) {
|
||||
global $DB, $OUTPUT;
|
||||
|
||||
if ($recordid) {
|
||||
if ($formdata) {
|
||||
$fieldname = 'field_' . $this->field->id . '_day';
|
||||
$day = $formdata->$fieldname;
|
||||
$fieldname = 'field_' . $this->field->id . '_month';
|
||||
$month = $formdata->$fieldname;
|
||||
$fieldname = 'field_' . $this->field->id . '_year';
|
||||
$year = $formdata->$fieldname;
|
||||
$content = make_timestamp($year, $month, $day, 12, 0, 0, 0, false);
|
||||
} else if ($recordid) {
|
||||
$content = (int)$DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid));
|
||||
} else {
|
||||
$content = time();
|
||||
}
|
||||
|
||||
$str = '<div title="'.s($this->field->description).'">';
|
||||
$str = '';
|
||||
if ($this->field->required) {
|
||||
$str .= '<div title="' . get_string('requiredfieldhint', 'data', s($this->field->description)) . '">';
|
||||
} else {
|
||||
$str .= '<div title="' . s($this->field->description) . '">';
|
||||
}
|
||||
$dayselector = html_writer::select_time('days', 'field_'.$this->field->id.'_day', $content);
|
||||
$monthselector = html_writer::select_time('months', 'field_'.$this->field->id.'_month', $content);
|
||||
$yearselector = html_writer::select_time('years', 'field_'.$this->field->id.'_year', $content);
|
||||
@@ -128,5 +141,3 @@ class data_field_date extends data_field_base {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user