Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
289 changes: 163 additions & 126 deletions packages/core/src/baseeditableholder/BaseEditableHolder.vue
Original file line number Diff line number Diff line change
@@ -1,136 +1,173 @@
<script>
import { isNotEmpty } from '@primeuix/utils';
import BaseComponent from '@primevue/core/basecomponent';

import { isNotEmpty } from "@primeuix/utils";
import BaseComponent from "@primevue/core/basecomponent";
export default {
name: 'BaseEditableHolder',
extends: BaseComponent,
emits: ['update:modelValue', 'value-change'],
props: {
modelValue: {
type: null,
default: undefined
},
defaultValue: {
type: null,
default: undefined
},
name: {
type: String,
default: undefined
},
invalid: {
type: Boolean,
default: undefined
},
disabled: {
type: Boolean,
default: false
},
formControl: {
type: Object,
default: undefined
}
name: "BaseEditableHolder",
extends: BaseComponent,
emits: ["update:modelValue", "value-change"],
props: {
modelValue: {
type: null,
default: undefined,
},
inject: {
$parentInstance: {
default: undefined
},
$pcForm: {
default: undefined
},
$pcFormField: {
default: undefined
}
defaultValue: {
type: null,
default: undefined,
},
data() {
return {
d_value: this.defaultValue !== undefined ? this.defaultValue : this.modelValue
};
},
watch: {
modelValue: {
deep: true,
handler(newValue) {
this.d_value = newValue;
}
},
defaultValue(newValue) {
this.d_value = newValue;
},
$formName: {
immediate: true,
handler(newValue) {
this.formField = this.$pcForm?.register?.(newValue, this.$formControl) || {};
}
},
$formControl: {
immediate: true,
handler(newValue) {
this.formField = this.$pcForm?.register?.(this.$formName, newValue) || {};
}
},
$formDefaultValue: {
immediate: true,
handler(newValue) {
this.d_value !== newValue && (this.d_value = newValue);
}
},
$formValue: {
immediate: false,
handler(newValue) {
if (this.$pcForm?.getFieldState(this.$formName) && newValue !== this.d_value) {
this.d_value = newValue;
}
}
}
name: {
type: String,
default: undefined,
},
invalid: {
type: Boolean,
default: undefined,
},
disabled: {
type: Boolean,
default: false,
},
formControl: {
type: Object,
default: undefined,
},
},
inject: {
$parentInstance: {
default: undefined,
},
$pcForm: {
default: undefined,
},
$pcFormField: {
default: undefined,
},
},
data() {
return {
d_value:
this.defaultValue !== undefined ? this.defaultValue : this.modelValue,
};
},
watch: {
modelValue: {
deep: true,
handler(newValue) {
this.d_value = newValue;
},
},
defaultValue(newValue) {
this.d_value = newValue;
},
$formName: {
immediate: true,
handler(newValue) {
this.formField =
this.$pcForm?.register?.(newValue, this.$formControl) || {};
},
},
$formControl: {
immediate: true,
handler(newValue) {
this.formField =
this.$pcForm?.register?.(this.$formName, newValue) || {};
},
},
formField: {},
methods: {
writeValue(value, event) {
if (this.controlled) {
this.d_value = value;
this.$emit('update:modelValue', value);
}

this.$emit('value-change', value);

this.formField.onChange?.({ originalEvent: event, value });
},
// @todo move to @primeuix/utils
findNonEmpty(...values) {
return values.find(isNotEmpty);
$formDefaultValue: {
immediate: true,
handler(newValue) {
if (this.d_value !== newValue) {
this.d_value = newValue;
// FIX: déclenche la mise à jour visuelle de l'input
// pour les composants comme DatePicker qui ont updateInputfield()
this.$nextTick(() => {
this.updateInputfield?.();
});
}
},
},
computed: {
$filled() {
return isNotEmpty(this.d_value);
},
$invalid() {
return !this.$formNovalidate && this.findNonEmpty(this.invalid, this.$pcFormField?.$field?.invalid, this.$pcForm?.getFieldState(this.$formName)?.invalid);
},
$formName() {
return !this.$formNovalidate ? this.name || this.$formControl?.name : undefined;
},
$formControl() {
return this.formControl || this.$pcFormField?.formControl;
},
$formNovalidate() {
return this.$formControl?.novalidate;
},
$formDefaultValue() {
return this.findNonEmpty(this.d_value, this.$pcFormField?.initialValue, this.$pcForm?.initialValues?.[this.$formName]);
},
$formValue() {
return this.findNonEmpty(this.$pcFormField?.$field?.value, this.$pcForm?.getFieldState(this.$formName)?.value);
},
controlled() {
return this.$inProps.hasOwnProperty('modelValue') || (!this.$inProps.hasOwnProperty('modelValue') && !this.$inProps.hasOwnProperty('defaultValue'));
},
// @deprecated use $filled instead
filled() {
return this.$filled;
$formValue: {
immediate: false,
handler(newValue) {
if (
this.$pcForm?.getFieldState(this.$formName) &&
newValue !== this.d_value
) {
this.d_value = newValue;
// FIX: idem for programatic update via setFieldValue
this.$nextTick(() => {
this.updateInputfield?.(); // updated DatePicker value
});
}
}
},
},
},
formField: {},
methods: {
writeValue(value, event) {
if (this.controlled) {
this.d_value = value;
this.$emit("update:modelValue", value);
}
this.$nextTick(() => {
this.updateInputfield?.();
});
this.$emit("value-change", value);
this.formField.onChange?.({ originalEvent: event, value });
},
// @todo move to @primeuix/utils
findNonEmpty(...values) {
return values.find(isNotEmpty);
},
},
computed: {
$filled() {
return isNotEmpty(this.d_value);
},
$invalid() {
return (
!this.$formNovalidate &&
this.findNonEmpty(
this.invalid,
this.$pcFormField?.$field?.invalid,
this.$pcForm?.getFieldState(this.$formName)?.invalid,
)
);
},
$formName() {
return !this.$formNovalidate
? this.name || this.$formControl?.name
: undefined;
},
$formControl() {
return this.formControl || this.$pcFormField?.formControl;
},
$formNovalidate() {
return this.$formControl?.novalidate;
},
$formDefaultValue() {
return this.findNonEmpty(
this.d_value,
this.$pcFormField?.initialValue,
this.$pcForm?.initialValues?.[this.$formName],
);
},
$formValue() {
return this.findNonEmpty(
this.$pcFormField?.$field?.value,
this.$pcForm?.getFieldState(this.$formName)?.value,
);
},
controlled() {
return (
this.$inProps.hasOwnProperty("modelValue") ||
(!this.$inProps.hasOwnProperty("modelValue") &&
!this.$inProps.hasOwnProperty("defaultValue"))
);
},
// @deprecated use $filled instead
filled() {
return this.$filled;
},
},
};
</script>
17 changes: 16 additions & 1 deletion packages/primevue/src/datepicker/DatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,21 @@ export default {
}
}
},
// FIX: sync rawValue and input display when d_value changes via Form initialValues
d_value: {
immediate: true,
handler(newValue) {
if (newValue === this.modelValue) return;
this.rawValue = typeof newValue === 'string' ? this.safeParse(newValue) : newValue;
this.updateCurrentMetaData();
if (!this.inline && this.input) {
this.input.value = this.formatValue(this.rawValue);
}
if (this.$refs.clearIcon?.$el?.style) {
this.$refs.clearIcon.$el.style.display = isEmpty(newValue) ? 'none' : 'block';
}
}
},
showTime() {
this.updateCurrentMetaData();
},
Expand Down Expand Up @@ -3302,4 +3317,4 @@ export default {
ripple: Ripple
}
};
</script>
</script>