Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add possibility to overwrite computed value #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion src/interface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:collection="collection"
:primary-key="primaryKey"
:model-value="value"
@update:model-value="$emit('input', $event)"
@update:model-value="onInput"
/>
<v-notice v-if="errorMsg" type="danger">{{ errorMsg }}</v-notice>
</template>
Expand Down Expand Up @@ -83,6 +83,7 @@ export default defineComponent({
const computedValue = ref<string | number | null>(props.value);
const relations = useCollectionRelations(props.collection);
const { collection, field, primaryKey } = toRefs(props)
const isComputedEditing = ref(true);

const values = useDeepValues(
inject<ComputedRef<Record<string, any>>>('values')!,
Expand All @@ -96,6 +97,11 @@ export default defineComponent({

if (values) {
watch(values, () => {
if (isComputedEditing.value) {
isComputedEditing.value = false
return
}

const newValue = compute();
computedValue.value = newValue;

Expand All @@ -116,6 +122,7 @@ export default defineComponent({
return {
computedValue,
errorMsg,
onInput,
};

function compute() {
Expand All @@ -139,6 +146,11 @@ export default defineComponent({
return null;
}
}

function onInput(value: string) {
isComputedEditing.value = true;
emit('input', value);
}
},
});
</script>