diff --git a/modules/instrument_builder/jsx/react.questions.js b/modules/instrument_builder/jsx/react.questions.js index a7c3cc1a63b..b9431591e67 100644 --- a/modules/instrument_builder/jsx/react.questions.js +++ b/modules/instrument_builder/jsx/react.questions.js @@ -996,12 +996,60 @@ class AddElement extends Component { }); } + if (questionName.length > 64 && selected !== 'textbox' + && selected !== 'textarea' && selected !== 'date' + && selected !== 'numeric') { + // Error, question name is needed for the desired type. Set the element + // error flag for the questionName with message. Set the hasError flag + let temp = (this.state.error) ? this.state.error : {}; + temp.questionName = 'Please shorten to 64 characters maximum'; + this.setState({ + error: temp, + }); + hasError = true; + } else if (this.state.error) { + // No error, remove the element's questionName error flag if set + let temp = this.state.error; + delete temp.questionName; + this.setState({ + error: temp, + }); + } + if (hasError) { + // An error is present, return + return; + } + + if (questionName.length > 57 && (selected === 'textbox' + || selected === 'textarea' || selected === 'date' + || selected === 'numeric')) { + // Error, question name is needed for the desired type. Set the element + // error flag for the questionName with message. Set the hasError flag + let temp = (this.state.error) ? this.state.error : {}; + temp.questionName = 'Please shorten to 57 characters maximum'; + this.setState({ + error: temp, + }); + hasError = true; + } else if (this.state.error) { + // No error, remove the elememt's questionName error flag if set + let temp = this.state.error; + delete temp.questionName; + this.setState({ + error: temp, + }); + } + if (hasError) { + // An error is present, return + return; + } + if (questionName === '' && selected !== 'header' && selected !== 'label' && selected !== 'line' && selected !== 'page-break') { // Error, question name is needed for the desired type. Set the element // error flag for the questionName with message. Set the hasError flag let temp = (this.state.error) ? this.state.error : {}; - temp.questionName = 'Must specifiy name for database to save value into'; + temp.questionName = 'Must specify name for database to save value into'; this.setState({ error: temp, }); diff --git a/modules/instrument_builder/test/TestPlan.md b/modules/instrument_builder/test/TestPlan.md index 22ccab6ae97..d37697d84c9 100644 --- a/modules/instrument_builder/test/TestPlan.md +++ b/modules/instrument_builder/test/TestPlan.md @@ -4,21 +4,32 @@ Instrument builder Test Plan * 1.a Add Header * 1.b Add Label * 1.c Add Scored Field - * 1.c.1 Validate that this requires both QuestionName and QuestionText + * 1.c.1 Validate that this requires both QuestionName and QuestionText + * 1.c.2 Validate that both QuestionName and QuestionText require less than 65 characters * 1.d Add Textbox - * 1.d.1 Validate that this requires both QuestionName and QuestionText + * 1.d.1 Validate that this requires both QuestionName and QuestionText + * 1.d.2 Validate that QuestionName requires less than 58 characters + * 1.d.3 Validate that QuestionText requires less than 65 characters * 1.e Add Textarea - * 1.e.1 Validate that this requires both QuestionName and QuestionText + * 1.e.1 Validate that this requires both QuestionName and QuestionText + * 1.e.2 Validate that QuestionName requires less than 58 characters + * 1.e.3 Validate that QuestionText requires less than 65 characters * 1.f Add Dropdown - * 1.f.1 Validate that this requires both QuestionName and QuestionText + * 1.f.1 Validate that this requires both QuestionName and QuestionText + * 1.f.2 Validate that both QuestionName and QuestionText require less than 65 characters * 1.g Add Multiselect - * 1.g.1 Validate that this requires both QuestionName and QuestionText + * 1.g.1 Validate that this requires both QuestionName and QuestionText + * 1.g.2 Validate that both QuestionName and QuestionText require less than 65 characters * 1.h Add Date * 1.h.1 Validate that this requires both QuestionName and QuestionText * 1.h.2 Validate adding range (startyear-endyear) + * 1.h.3 Validate that QuestionName requires less than 58 characters + * 1.h.4 Validate that QuestionText requires less than 65 characters * 1.i Add Numeric * 1.i.1 Validate that this requires both QuestionName and QuestionText * 1.i.2 Validate adding range + * 1.i.3 Validate that QuestionName requires less than 58 characters + * 1.i.4 Validate that QuestionText requires less than 65 characters * 1.j Add Blank Line * 1.k Add Page break 2. Edit Question Name and Question Text in the table directly and check if it sticks.