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

inc/fields/textfield.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>';
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/urgencyfield.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getDesignSpecializationField() {
5050
$additions .= '<td>';
5151
$additions .= Ticket::dropdownUrgency([
5252
'name' => 'default_values',
53-
'value' => $this->questoin->fields['default_values'],
53+
'value' => $this->question->fields['default_values'],
5454
'comments' => false,
5555
'rand' => $rand,
5656
'display' => false,

js/scripts.js.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,14 @@ function plugin_formcreator_removeNextCondition(target) {
776776

777777
function plugin_formcreator_changeDropdownItemtype(rand) {
778778
dropdown_type = $('[name="form_question"] [name="dropdown_values"]').val();
779+
dropdown_id = $('[name="form_question"] [name="id"]').val();
779780

780781
$.ajax({
781782
url: rootDoc + '/plugins/formcreator/ajax/dropdown_values.php',
782783
type: 'GET',
783784
data: {
784785
dropdown_itemtype: dropdown_type,
786+
'id': dropdown_id
785787
},
786788
}).done(function(response) {
787789
showTicketCategorySpecific = false;
@@ -794,13 +796,15 @@ function plugin_formcreator_changeDropdownItemtype(rand) {
794796
}
795797

796798
function plugin_formcreator_changeGlpiObjectItemType() {
797-
glpi_object = $('[name="form_question"] [name="glpi_objects"]').val();
799+
glpi_object = $('[name="form_question"] [name="glpi_objects"]').val();
800+
glpi_object_id = $('[name="form_question"] [name="id"]').val();
798801

799802
$.ajax({
800803
url: rootDoc + '/plugins/formcreator/ajax/dropdown_values.php',
801804
type: 'GET',
802805
data: {
803806
dropdown_itemtype: glpi_object,
807+
id: glpi_object_id
804808
},
805809
}).done(function(response) {
806810
$('#dropdown_default_value_field').html(response);

0 commit comments

Comments
 (0)