-
Notifications
You must be signed in to change notification settings - Fork 51
/
objectIteration.js
22 lines (22 loc) · 964 Bytes
/
objectIteration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//OLD
if (newVal === 3 || newVal === 4 || newVal === 7) {
mform.setMandatory('resolution_code', true);
mform.setMandatory('resolution_detail', true);
mform.setMandatory('service_date', true);
} else {
mform.setMandatory('resolution_code', false);
mform.setMandatory('resolution_detail', false);
mform.setMandatory('service_date', false);
}
//REFACTORED
// Capture closure states into its own array
var closureStates = [3, 4, 7];
// Verify the current state is one of the closure states
var requiresClosureFields = newState.indexOf(closureStates) > -1;
// Capture fields to mandate on closure into its own array
var closureFields = ["resolution_code", "resolution_detail", "service_date"];
// Now we can write generic code to set mandatory state on resolution fields based on resolution state
for (var cf = 0; cf < closureFields.length; cf++) {
var thisClosureField = closureFields[cf];
mform.setMandatory(thisClosureField, requiresClosureFields);
}