Skip to content

Commit 1304d9e

Browse files
spinna2902793
andauthored
Enhancements for optional questions (#153)
* Show OK button if question is not required * Changed OK button text from "Ok" to "Skip" if not required questions have no value * Clean up validation and optional questions * Fix validation when a mask is defined Co-authored-by: Johnny Yeng <[email protected]>
1 parent 2424cf0 commit 1304d9e

File tree

5 files changed

+26
-5
lines changed

5 files changed

+26
-5
lines changed

src/components/Question.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@
7171
v-bind:aria-label="language.ariaOk"
7272
>
7373
<span v-if="question.type === QuestionType.SectionBreak">{{ language.continue }}</span>
74-
<span v-else>{{ language.ok }}</span>
74+
<span v-else>
75+
<span v-if="showSkip()">{{ language.skip }}</span>
76+
<span v-else>{{ language.ok }}</span>
77+
</span>
7578
</button>
7679
<a
7780
class="f-enter-desc"
@@ -245,6 +248,10 @@
245248
return this.active
246249
}
247250
251+
if (!this.question.required) {
252+
return true
253+
}
254+
248255
if (this.question.allowOther && this.question.other) {
249256
return true
250257
}
@@ -262,6 +269,12 @@
262269
return q.hasValue && q.isValid()
263270
},
264271
272+
showSkip() {
273+
const q = this.$refs.questionComponent
274+
275+
return q && !this.question.required && !q.hasValue
276+
},
277+
265278
/**
266279
* Determins if the invalid message should be shown.
267280
*/

src/components/QuestionTypes/EmailType.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
},
1919
methods: {
2020
validate() {
21-
return this.hasValue && /^[^@]+@.+[^.]$/.test(this.dataValue)
21+
if (this.hasValue) {
22+
return /^[^@]+@.+[^.]$/.test(this.dataValue)
23+
}
24+
25+
return !this.question.required
2226
}
2327
}
2428
}

src/components/QuestionTypes/TextType.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
6868
methods: {
6969
validate() {
70-
if (this.question.mask && this.dataValue.length !== this.question.mask.length) {
70+
if (this.question.mask && this.hasValue && this.dataValue.length !== this.question.mask.length) {
7171
return false
7272
}
7373

src/components/QuestionTypes/UrlType.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@
3333
var url = new URL(this.fixAnswer(this.dataValue))
3434
3535
return true
36-
} catch(_) { /* Invalid URL */ }
36+
} catch(_) {
37+
// Invalid URL
38+
return false
39+
}
3740
}
3841
39-
return false
42+
return !this.question.required
4043
}
4144
}
4245
}

src/models/LanguageModel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default class LanguageModel {
1212
this.shiftKey = 'Shift'
1313
this.ok = 'OK'
1414
this.continue = 'Continue'
15+
this.skip = 'Skip'
1516
this.pressEnter = 'Press :enterKey'
1617
this.multipleChoiceHelpText = 'Choose as many as you like'
1718
this.multipleChoiceHelpTextSingle = 'Choose only one answer'

0 commit comments

Comments
 (0)