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.formField.onChange?.({ originalEvent: event, value });
},
// @todo move to @primeuix/utils
findNonEmpty(...values) {
return values.find(isNotEmpty);
}
},
computed: {
@ -100,7 +104,7 @@ export default {
return isNotEmpty(this.d_value);
},
$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() {
return this.name || this.$formControl?.name;
@ -109,10 +113,10 @@ export default {
return this.formControl || this.$pcFormField?.formControl;
},
$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() {
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() {
return this.$inProps.hasOwnProperty('modelValue') || (!this.$inProps.hasOwnProperty('modelValue') && !this.$inProps.hasOwnProperty('defaultValue'));