Skip to content

Commit f05f2de

Browse files
committed
fix(field): default value for most fields
1 parent 58f0f18 commit f05f2de

13 files changed

+46
-17
lines changed

ajax/dropdown_values.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,21 @@
3636
if (!isset($_REQUEST['dropdown_itemtype'])
3737
|| $_REQUEST['dropdown_itemtype'] == '0'
3838
|| !class_exists($_REQUEST['dropdown_itemtype'])) {
39-
Dropdown::showFromArray('dropdown_default_value', [], ['display_emptychoice' => true]);
39+
Dropdown::showFromArray(
40+
'dropdown_default_value',
41+
[], [
42+
'display_emptychoice' => true
43+
]
44+
);
4045
} else {
46+
$question = new PluginFormcreatorQuestion();
47+
$question->getFromDB((int) $_REQUEST['id']);
48+
$defaultValue = isset($question->fields['default_values'])
49+
? $question->fields['default_values']
50+
: 0;
4151
Dropdown::show($_REQUEST['dropdown_itemtype'], [
42-
'name' => 'dropdown_default_value',
43-
'rand' => mt_rand(),
52+
'name' => 'dropdown_default_value',
53+
'rand' => mt_rand(),
54+
'value' => $defaultValue,
4455
]);
45-
$showTicketCategorySpecific = ($_REQUEST['dropdown_itemtype'] == ITILCategory::class)
46-
? 'true'
47-
: 'false';
4856
}

inc/fields/actorfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function getDesignSpecializationField() {
5656
$additions .= '<td>';
5757
$additions .= '<textarea name="default_values" id="default_values" rows="4" cols="40"'
5858
.'style="width: 90%">'
59-
.$this->getValueForDesign()
59+
.$this->question->fields['default_values']
6060
.'</textarea>';
6161
$additions .= '</td>';
6262
$additions .= '<td>';

inc/fields/checkboxesfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getDesignSpecializationField() {
5151
$additions .= '<td>';
5252
$additions .= '<textarea name="default_values" id="default_values" rows="4" cols="40"'
5353
.'style="width: 90%">'
54-
.$this->getValueForDesign()
54+
.$this->question->fields['default_values']
5555
.'</textarea>';
5656
$additions .= '</td>';
5757
$additions .= '<td>';

inc/fields/floatfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getDesignSpecializationField() {
4848
$additions .= '</label>';
4949
$additions .= '</td>';
5050
$additions .= '<td id="dropdown_default_value_field">';
51-
$value = Html::entities_deep($this->getValueForDesign());
51+
$value = Html::entities_deep($this->question->fields['default_values']);
5252
$additions .= '<input type="text" name="default_values" id="default_values" rows="4" cols="40"'
5353
.'style="width: 90%" value="'.$value.'">';
5454
$additions .= '</td>';

inc/fields/glpiselectfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function getDesignSpecializationField() {
9393
$additions .= '<td></td>';
9494
$additions .= '<td></td>';
9595
$additions .= '</tr>';
96-
96+
$additions .= Html::scriptBlock("plugin_formcreator_changeGlpiObjectItemType($rand);");
9797
return [
9898
'label' => $label,
9999
'field' => $field,

inc/fields/hiddenfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function getDesignSpecializationField() {
4545
$additions .= '</label>';
4646
$additions .= '</td>';
4747
$additions .= '<td id="dropdown_default_value_field">';
48-
$value = Html::entities_deep($this->getValueForDesign());
48+
$value = Html::entities_deep($this->question->fields['default_values']);
4949
$additions .= '<input type="text" name="default_values" id="default_values" rows="4" cols="40"'
5050
.'style="width: 90%" value="'.$value.'">';
5151
$additions .= '</td>';

inc/fields/integerfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getDesignSpecializationField() {
4848
$additions .= '</label>';
4949
$additions .= '</td>';
5050
$additions .= '<td id="dropdown_default_value_field">';
51-
$value = Html::entities_deep($this->getValueForDesign());
51+
$value = Html::entities_deep($this->question->fields['default_values']);
5252
$additions .= '<input type="text" name="default_values" id="default_values" rows="4" cols="40"'
5353
.'style="width: 90%" value="'.$value.'">';
5454
$additions .= '</td>';

inc/fields/multiselectfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getDesignSpecializationField() {
5151
$additions .= '<td>';
5252
$additions .= '<textarea name="default_values" id="default_values" rows="4" cols="40"'
5353
.'style="width: 90%">'
54-
.$this->getValueForDesign()
54+
.$this->question->fields['default_values']
5555
.'</textarea>';
5656
$additions .= '</td>';
5757
$additions .= '<td>';

inc/fields/radiosfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function getDesignSpecializationField() {
5151
$additions .= '<td>';
5252
$additions .= '<textarea name="default_values" id="default_values" rows="4" cols="40"'
5353
.'style="width: 90%">'
54-
.$this->getValueForDesign()
54+
.$this->question->fields['default_values']
5555
.'</textarea>';
5656
$additions .= '</td>';
5757
$additions .= '<td>';

inc/fields/tagfield.class.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,23 @@ public function isPrerequisites() {
3535
return class_exists(PluginTagTag::class);
3636
}
3737

38+
public function getDesignSpecializationField() {
39+
$rand = mt_rand();
40+
41+
$label = '';
42+
$field = '';
43+
44+
$additions = '';
45+
46+
return [
47+
'label' => $label,
48+
'field' => $field,
49+
'additions' => $additions,
50+
'may_be_empty' => false,
51+
'may_be_required' => true,
52+
];
53+
}
54+
3855
public function displayField($canEdit = true) {
3956
global $DB;
4057

0 commit comments

Comments
 (0)