Fixed #1849 - Deprecate keepInvalid of Calendar

pull/1885/head
Cagatay Civici 2021-12-07 12:50:14 +03:00
parent a6e71f84a6
commit 87724dcd2a
2 changed files with 26 additions and 16 deletions

View File

@ -1,7 +1,7 @@
<template> <template>
<span ref="container" :class="containerClass" :style="style"> <span ref="container" :class="containerClass" :style="style">
<CalendarInputText ref="input" v-if="!inline" type="text" v-bind="$attrs" :value="inputFieldValue" @input="onInput" @focus="onFocus" @blur="onBlur" @keydown="onKeyDown" :readonly="!manualInput" inputmode="none" <input :ref="inputRef" v-if="!inline" type="text" :class="['p-inputtext p-component', inputClass]" :style="inputStyle" @input="onInput" v-bind="$attrs"
:class="inputClass" :style="inputStyle" /> @focus="onFocus" @blur="onBlur" @keydown="onKeyDown" :readonly="!manualInput" inputmode="none">
<CalendarButton v-if="showIcon" :icon="icon" tabindex="-1" class="p-datepicker-trigger" :disabled="$attrs.disabled" @click="onButtonClick" type="button" :aria-label="inputFieldValue"/> <CalendarButton v-if="showIcon" :icon="icon" tabindex="-1" class="p-datepicker-trigger" :disabled="$attrs.disabled" @click="onButtonClick" type="button" :aria-label="inputFieldValue"/>
<Teleport :to="appendTarget" :disabled="appendDisabled"> <Teleport :to="appendTarget" :disabled="appendDisabled">
<transition name="p-connected-overlay" @enter="onOverlayEnter($event)" @after-enter="onOverlayEnterComplete" @after-leave="onOverlayAfterLeave" @leave="onOverlayLeave"> <transition name="p-connected-overlay" @enter="onOverlayEnter($event)" @after-enter="onOverlayEnterComplete" @after-leave="onOverlayAfterLeave" @leave="onOverlayLeave">
@ -144,7 +144,6 @@
<script> <script>
import {ConnectedOverlayScrollHandler,DomHandler,ZIndexUtils,UniqueComponentId} from 'primevue/utils'; import {ConnectedOverlayScrollHandler,DomHandler,ZIndexUtils,UniqueComponentId} from 'primevue/utils';
import OverlayEventBus from 'primevue/overlayeventbus'; import OverlayEventBus from 'primevue/overlayeventbus';
import InputText from 'primevue/inputtext';
import Button from 'primevue/button'; import Button from 'primevue/button';
import Ripple from 'primevue/ripple'; import Ripple from 'primevue/ripple';
@ -315,9 +314,11 @@ export default {
maskClickListener: null, maskClickListener: null,
resizeListener: null, resizeListener: null,
overlay: null, overlay: null,
input: null,
mask: null, mask: null,
timePickerTimer: null, timePickerTimer: null,
preventFocus: false, preventFocus: false,
typeUpdate: false,
created() { created() {
this.updateCurrentMetaData(); this.updateCurrentMetaData();
}, },
@ -335,6 +336,9 @@ export default {
} }
} }
} }
else {
this.input.value = this.formatValue(this.modelValue);
}
}, },
updated() { updated() {
if (this.overlay) { if (this.overlay) {
@ -342,9 +346,9 @@ export default {
this.updateFocus(); this.updateFocus();
} }
if (this.$refs.input && this.selectionStart != null && this.selectionEnd != null) { if (this.input && this.selectionStart != null && this.selectionEnd != null) {
this.$refs.input.$el.selectionStart = this.selectionStart; this.input.selectionStart = this.selectionStart;
this.$refs.input.$el.selectionEnd = this.selectionEnd; this.input.selectionEnd = this.selectionEnd;
this.selectionStart = null; this.selectionStart = null;
this.selectionEnd = null; this.selectionEnd = null;
} }
@ -386,8 +390,12 @@ export default {
} }
}, },
watch: { watch: {
modelValue() { modelValue(newValue) {
this.updateCurrentMetaData(); this.updateCurrentMetaData();
if (!this.typeUpdate && !this.inline && this.input) {
this.input.value = this.formatValue(newValue);
}
this.typeUpdate = false;
}, },
showTime() { showTime() {
this.updateCurrentMetaData(); this.updateCurrentMetaData();
@ -804,7 +812,7 @@ export default {
onButtonClick() { onButtonClick() {
if (this.isEnabled()) { if (this.isEnabled()) {
if (!this.overlayVisible) { if (!this.overlayVisible) {
this.$refs.input.$el.focus(); this.input.focus();
this.overlayVisible = true; this.overlayVisible = true;
} }
else { else {
@ -2155,18 +2163,17 @@ export default {
}, },
onInput(event) { onInput(event) {
try { try {
this.selectionStart = this.$refs.input.$el.selectionStart; this.selectionStart = this.input.selectionStart;
this.selectionEnd = this.$refs.input.$el.selectionEnd; this.selectionEnd = this.input.selectionEnd;
let value = this.parseValue(event.target.value); let value = this.parseValue(event.target.value);
if (this.isValidSelection(value)) { if (this.isValidSelection(value)) {
this.typeUpdate = true;
this.updateModel(value); this.updateModel(value);
} }
} }
catch(err) { catch(err) {
if (this.keepInvalid) { /* NoOp */
this.updateModel(event.target.value);
}
} }
}, },
onFocus() { onFocus() {
@ -2177,6 +2184,7 @@ export default {
}, },
onBlur() { onBlur() {
this.focused = false; this.focused = false;
this.input.value = this.formatValue(this.modelValue);
}, },
onKeyDown() { onKeyDown() {
if (event.keyCode === 40 && this.overlay) { if (event.keyCode === 40 && this.overlay) {
@ -2201,6 +2209,9 @@ export default {
overlayRef(el) { overlayRef(el) {
this.overlay = el; this.overlay = el;
}, },
inputRef(el) {
this.input = el;
},
getMonthName(index) { getMonthName(index) {
return this.$primevue.config.locale.monthNames[index]; return this.$primevue.config.locale.monthNames[index];
}, },
@ -2477,7 +2488,6 @@ export default {
} }
}, },
components: { components: {
'CalendarInputText': InputText,
'CalendarButton': Button 'CalendarButton': Button
}, },
directives: { directives: {

View File

@ -442,10 +442,10 @@ export default {
<td>Style class of the component.</td> <td>Style class of the component.</td>
</tr> </tr>
<tr> <tr>
<td>keepInvalid</td> <td>keepInvalid (Deprecated)</td>
<td>boolean</td> <td>boolean</td>
<td>false</td> <td>false</td>
<td>Keep invalid value when input blur.</td> <td>Keep invalid value when input blur. <b>Deprecated</b>: Invalid values are not kept anymore.</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>