Skip to content

Commit 5e28a5c

Browse files
[instrument_builder] ADDED: field warnings for maximum length in Instrument Builder module (#8112)
Add maximum field name length to ensure that it doesn't go higher than the MySQL column name size limit.
1 parent 26f117c commit 5e28a5c

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

modules/instrument_builder/jsx/react.questions.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,12 +996,60 @@ class AddElement extends Component {
996996
});
997997
}
998998

999+
if (questionName.length > 64 && selected !== 'textbox'
1000+
&& selected !== 'textarea' && selected !== 'date'
1001+
&& selected !== 'numeric') {
1002+
// Error, question name is needed for the desired type. Set the element
1003+
// error flag for the questionName with message. Set the hasError flag
1004+
let temp = (this.state.error) ? this.state.error : {};
1005+
temp.questionName = 'Please shorten to 64 characters maximum';
1006+
this.setState({
1007+
error: temp,
1008+
});
1009+
hasError = true;
1010+
} else if (this.state.error) {
1011+
// No error, remove the element's questionName error flag if set
1012+
let temp = this.state.error;
1013+
delete temp.questionName;
1014+
this.setState({
1015+
error: temp,
1016+
});
1017+
}
1018+
if (hasError) {
1019+
// An error is present, return
1020+
return;
1021+
}
1022+
1023+
if (questionName.length > 57 && (selected === 'textbox'
1024+
|| selected === 'textarea' || selected === 'date'
1025+
|| selected === 'numeric')) {
1026+
// Error, question name is needed for the desired type. Set the element
1027+
// error flag for the questionName with message. Set the hasError flag
1028+
let temp = (this.state.error) ? this.state.error : {};
1029+
temp.questionName = 'Please shorten to 57 characters maximum';
1030+
this.setState({
1031+
error: temp,
1032+
});
1033+
hasError = true;
1034+
} else if (this.state.error) {
1035+
// No error, remove the elememt's questionName error flag if set
1036+
let temp = this.state.error;
1037+
delete temp.questionName;
1038+
this.setState({
1039+
error: temp,
1040+
});
1041+
}
1042+
if (hasError) {
1043+
// An error is present, return
1044+
return;
1045+
}
1046+
9991047
if (questionName === '' && selected !== 'header' && selected !== 'label' &&
10001048
selected !== 'line' && selected !== 'page-break') {
10011049
// Error, question name is needed for the desired type. Set the element
10021050
// error flag for the questionName with message. Set the hasError flag
10031051
let temp = (this.state.error) ? this.state.error : {};
1004-
temp.questionName = 'Must specifiy name for database to save value into';
1052+
temp.questionName = 'Must specify name for database to save value into';
10051053
this.setState({
10061054
error: temp,
10071055
});

modules/instrument_builder/test/TestPlan.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,32 @@ Instrument builder Test Plan
44
* 1.a Add Header
55
* 1.b Add Label
66
* 1.c Add Scored Field
7-
* 1.c.1 Validate that this requires both QuestionName and QuestionText
7+
* 1.c.1 Validate that this requires both QuestionName and QuestionText
8+
* 1.c.2 Validate that both QuestionName and QuestionText require less than 65 characters
89
* 1.d Add Textbox
9-
* 1.d.1 Validate that this requires both QuestionName and QuestionText
10+
* 1.d.1 Validate that this requires both QuestionName and QuestionText
11+
* 1.d.2 Validate that QuestionName requires less than 58 characters
12+
* 1.d.3 Validate that QuestionText requires less than 65 characters
1013
* 1.e Add Textarea
11-
* 1.e.1 Validate that this requires both QuestionName and QuestionText
14+
* 1.e.1 Validate that this requires both QuestionName and QuestionText
15+
* 1.e.2 Validate that QuestionName requires less than 58 characters
16+
* 1.e.3 Validate that QuestionText requires less than 65 characters
1217
* 1.f Add Dropdown
13-
* 1.f.1 Validate that this requires both QuestionName and QuestionText
18+
* 1.f.1 Validate that this requires both QuestionName and QuestionText
19+
* 1.f.2 Validate that both QuestionName and QuestionText require less than 65 characters
1420
* 1.g Add Multiselect
15-
* 1.g.1 Validate that this requires both QuestionName and QuestionText
21+
* 1.g.1 Validate that this requires both QuestionName and QuestionText
22+
* 1.g.2 Validate that both QuestionName and QuestionText require less than 65 characters
1623
* 1.h Add Date
1724
* 1.h.1 Validate that this requires both QuestionName and QuestionText
1825
* 1.h.2 Validate adding range (startyear-endyear)
26+
* 1.h.3 Validate that QuestionName requires less than 58 characters
27+
* 1.h.4 Validate that QuestionText requires less than 65 characters
1928
* 1.i Add Numeric
2029
* 1.i.1 Validate that this requires both QuestionName and QuestionText
2130
* 1.i.2 Validate adding range
31+
* 1.i.3 Validate that QuestionName requires less than 58 characters
32+
* 1.i.4 Validate that QuestionText requires less than 65 characters
2233
* 1.j Add Blank Line
2334
* 1.k Add Page break
2435
2. Edit Question Name and Question Text in the table directly and check if it sticks.

0 commit comments

Comments
 (0)