Skip to content

Commit 178a3fc

Browse files
Update autoPopulateSD.js
1) Variable names are shorter and clearer (category, currentShortDesc). 2) Used direct key access (prefixMap[category]) instead of hasOwnProperty. 3) Removed unnecessary comments (code is self-explanatory now).
1 parent 2d6bf22 commit 178a3fc

File tree

1 file changed

+5
-11
lines changed
  • Client-Side Components/Client Scripts/Auto-Populate Short Discription

1 file changed

+5
-11
lines changed
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
// Client Script to Auto-Populate Short Description based on Category
22

33
function onChangeCategory() {
4-
var categoryField = g_form.getValue('category'); // Get the selected category
5-
var shortDescriptionField = g_form.getValue('short_description'); // Get the Short Description field
4+
var category = g_form.getValue('category');
5+
var currentShortDesc = g_form.getValue('short_description');
66

7-
// Define mappings for categories and corresponding short descriptions
8-
var categoryToShortDescription = {
7+
var prefixMap = {
98
'Hardware': 'Hardware Issue - ',
109
'Software': 'Software Issue - ',
1110
'Network': 'Network Issue - ',
1211
'Other': 'Other Issue - '
1312
};
1413

15-
// Update Short Description based on the selected category
16-
if (categoryToShortDescription.hasOwnProperty(categoryField)) {
17-
var newShortDescription = categoryToShortDescription[categoryField] + shortDescriptionField;
18-
g_form.setValue('short_description', newShortDescription);
14+
if (prefixMap[category]) {
15+
g_form.setValue('short_description', prefixMap[category] + currentShortDesc);
1916
}
2017
}
21-
22-
// Attach the onChangeCategory function to the 'category' field
23-
g_form.observe('change', 'category', onChangeCategory);

0 commit comments

Comments
 (0)