Refactor #7049 - added findNonEmpty to track change detection

pull/7055/head
Mert Sincan 2025-01-07 10:16:02 +00:00
parent 0911e53973
commit 631ca11102
1 changed files with 7 additions and 3 deletions

View File

@ -93,6 +93,10 @@ export default {
this.$emit('value-change', value); this.$emit('value-change', value);
this.formField.onChange?.({ originalEvent: event, value }); this.formField.onChange?.({ originalEvent: event, value });
},
// @todo move to @primeuix/utils
findNonEmpty(...values) {
return values.find(isNotEmpty);
} }
}, },
computed: { computed: {
@ -100,7 +104,7 @@ export default {
return isNotEmpty(this.d_value); return isNotEmpty(this.d_value);
}, },
$invalid() { $invalid() {
return this.invalid ?? this.$pcFormField?.$field?.invalid ?? this.$pcForm?.states?.[this.$formName]?.invalid; return this.findNonEmpty(this.invalid, this.$pcFormField?.$field?.invalid, this.$pcForm?.states?.[this.$formName]?.invalid);
}, },
$formName() { $formName() {
return this.name || this.$formControl?.name; return this.name || this.$formControl?.name;
@ -109,10 +113,10 @@ export default {
return this.formControl || this.$pcFormField?.formControl; return this.formControl || this.$pcFormField?.formControl;
}, },
$formDefaultValue() { $formDefaultValue() {
return this.d_value ?? this.$pcFormField?.initialValue ?? this.$pcForm?.initialValues?.[this.$formName]; return this.findNonEmpty(this.d_value, this.$pcFormField?.initialValue, this.$pcForm?.initialValues?.[this.$formName]);
}, },
$formValue() { $formValue() {
return this.$pcFormField?.$field?.value ?? this.$pcForm?.states?.[this.$formName]?.value; return this.findNonEmpty(this.$pcFormField?.$field?.value, this.$pcForm?.states?.[this.$formName]?.value);
}, },
controlled() { controlled() {
return this.$inProps.hasOwnProperty('modelValue') || (!this.$inProps.hasOwnProperty('modelValue') && !this.$inProps.hasOwnProperty('defaultValue')); return this.$inProps.hasOwnProperty('modelValue') || (!this.$inProps.hasOwnProperty('modelValue') && !this.$inProps.hasOwnProperty('defaultValue'));