|
8 | 8 | v-bind="questionProps" |
9 | 9 | :titlePlaceholder="answerType.titlePlaceholder" |
10 | 10 | :warningInvalid="answerType.warningInvalid" |
| 11 | + :errorMessage="errorMessage" |
11 | 12 | v-on="commonListeners"> |
12 | 13 | <template v-if="answerType.pickerType === 'date'" #actions> |
13 | 14 | <NcActionCheckbox |
|
95 | 96 | :type="dateTimePickerType" |
96 | 97 | :disabledDate="disabledDates" |
97 | 98 | :disabledTime="disabledTimes" |
98 | | - rangeSeparator=" - " |
| 99 | + :aria-required="isRequired" |
| 100 | + clearable |
99 | 101 | @update:modelValue="onValueChange" /> |
100 | 102 | </div> |
101 | 103 | <template #insert> |
@@ -146,25 +148,31 @@ export default { |
146 | 148 | }, |
147 | 149 |
|
148 | 150 | computed: { |
| 151 | + isRangeQuestion() { |
| 152 | + return this.extraSettings?.dateRange || this.extraSettings?.timeRange |
| 153 | + ? true |
| 154 | + : false |
| 155 | + }, |
| 156 | +
|
149 | 157 | datetimePickerPlaceholder() { |
150 | 158 | if (this.readOnly) { |
151 | | - return this.extraSettings?.dateRange || this.extraSettings?.timeRange |
| 159 | + return this.isRangeQuestion |
152 | 160 | ? this.answerType.submitPlaceholderRange |
153 | 161 | : this.answerType.submitPlaceholder |
154 | 162 | } |
155 | | - return this.extraSettings?.dateRange || this.extraSettings?.timeRange |
| 163 | + return this.isRangeQuestion |
156 | 164 | ? this.answerType.createPlaceholderRange |
157 | 165 | : this.answerType.createPlaceholder |
158 | 166 | }, |
159 | 167 |
|
160 | 168 | dateTimePickerType() { |
161 | | - return this.extraSettings?.dateRange || this.extraSettings?.timeRange |
| 169 | + return this.isRangeQuestion |
162 | 170 | ? this.answerType.pickerType + '-range' |
163 | 171 | : this.answerType.pickerType |
164 | 172 | }, |
165 | 173 |
|
166 | 174 | time() { |
167 | | - if (this.extraSettings?.dateRange || this.extraSettings?.timeRange) { |
| 175 | + if (this.isRangeQuestion) { |
168 | 176 | return this.values?.[0] |
169 | 177 | ? [this.parse(this.values[0]), this.parse(this.values[1])] |
170 | 178 | : null |
@@ -224,14 +232,27 @@ export default { |
224 | 232 | }, |
225 | 233 |
|
226 | 234 | methods: { |
| 235 | + async validate() { |
| 236 | + if (this.isRequired && this.time === null) { |
| 237 | + this.errorMessage = t('forms', 'You must answer this question') |
| 238 | + return false |
| 239 | + } |
| 240 | +
|
| 241 | + this.errorMessage = null |
| 242 | + return true |
| 243 | + }, |
| 244 | +
|
227 | 245 | /** |
228 | 246 | * DateTimepicker show text in picker |
229 | 247 | * Format depends on component-type date/datetime |
230 | 248 | * |
231 | | - * @param {Date} date the selected datepicker Date |
| 249 | + * @param {Date|Date[]} date the selected datepicker Date |
232 | 250 | * @return {string} |
233 | 251 | */ |
234 | 252 | stringify(date) { |
| 253 | + if (this.isRangeQuestion && Array.isArray(date)) { |
| 254 | + return `${moment(date[0]).format(this.answerType.momentFormat)} - ${moment(date[1]).format(this.answerType.momentFormat)}` |
| 255 | + } |
235 | 256 | return moment(date).format(this.answerType.momentFormat) |
236 | 257 | }, |
237 | 258 |
|
@@ -335,10 +356,15 @@ export default { |
335 | 356 | /** |
336 | 357 | * Store Value |
337 | 358 | * |
338 | | - * @param {Date|Array<Date>} date The date or date range to store |
| 359 | + * @param {Date|Array<Date>|null} date The date or date range to store |
339 | 360 | */ |
340 | 361 | onValueChange(date) { |
341 | | - if (this.extraSettings?.dateRange || this.extraSettings?.timeRange) { |
| 362 | + if (!date) { |
| 363 | + this.$emit('update:values', []) |
| 364 | + return |
| 365 | + } |
| 366 | +
|
| 367 | + if (this.isRangeQuestion) { |
342 | 368 | this.$emit('update:values', [ |
343 | 369 | moment(date[0]).format(this.answerType.storageFormat), |
344 | 370 | moment(date[1]).format(this.answerType.storageFormat), |
|
0 commit comments