Skip to content

Commit

Permalink
fix(timefield): assign a default value
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Apr 28, 2020
1 parent 08c06ed commit 2b57477
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions inc/fields/timefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,52 @@ public function isPrerequisites() {
return true;
}

public function getDesignSpecializationField() {
$rand = mt_rand();

$label = '';
$field = '';

$additions = '<tr class="plugin_formcreator_question_specific">';
$additions .= '<td>';
$additions .= '<label for="dropdown_default_values'.$rand.'">';
$additions .= __('Default values');
$additions .= '</label>';
$additions .= '</td>';
$additions .= '<td>';
$value = Html::entities_deep($this->question->fields['default_values']);
if (version_compare(GLPI_VERSION, '9.5') >= 0 && method_exists(Html::class, 'showTimeField')) {
$additions .= Html::showTimeField('default_values', [
'type' => 'text',
'id' => 'default_values',
'value' => $value,
'display' => false,
]);
} else {
$additions .= static::showTimeField('default_values', [
'type' => 'text',
'id' => 'default_values',
'value' => $value,
'display' => false,
]);
}
$additions .= '</td>';
$additions .= '<td></td>';
$additions .= '<td></td>';
$additions .= '</tr>';

$common = parent::getDesignSpecializationField();
$additions .= $common['additions'];

return [
'label' => $label,
'field' => $field,
'additions' => $additions,
'may_be_empty' => false,
'may_be_required' => true,
];
}

public function displayField($canEdit = true) {
if ($canEdit) {
$id = $this->question->getID();
Expand Down Expand Up @@ -154,7 +200,7 @@ public function isAnonymousFormCompatible() {
}

/**
* Display TimeField form
* Display TimeField form
* @see Html::dateTime()
*
* @param string $name
Expand Down Expand Up @@ -194,7 +240,7 @@ protected static function showTimeField($name, $options = []) {
$p['timestep'] = $CFG_GLPI['time_step'];
}

// Those vars are set but not used ...
// Those vars are set but not used ...
// check Hml::showDateTimeField()

// $minHour = 0;
Expand Down

0 comments on commit 2b57477

Please sign in to comment.