-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vfg): input model reactivity (#1373)
* fix(vfg): input model reactivity * fix(*): reactivity logic and tester * fix(*): ts error * fix(*): keep model reactive and remove watcher (#1380) --------- Co-authored-by: Yi Yang <Leopoldthecoder@users.noreply.github.com>
- Loading branch information
1 parent
46b157a
commit c0c35ff
Showing
4 changed files
with
82 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<template> | ||
<div class="sandbox-container"> | ||
<h3>Controls</h3> | ||
<KInput | ||
v-model="defaultVal" | ||
label="Default" | ||
readonly | ||
/> | ||
<KInput | ||
v-model="newVal" | ||
label="New Value" | ||
/> | ||
|
||
<button @click="setNewVal"> | ||
Update Model | ||
</button> | ||
|
||
<h3>My Form</h3> | ||
<VueFormGenerator | ||
:model="formModel" | ||
:schema="formSchema" | ||
@model-updated="(model: Record<string, any>, schema: string) => handleModelUpdated(model, schema)" | ||
/> | ||
|
||
<code>{{ formModel }}</code> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref } from 'vue' | ||
const formSchema = ref({ | ||
fields: [ | ||
{ | ||
type: 'input', | ||
model: 'cat_name', | ||
inputType: 'text', | ||
label: 'Cat Name', | ||
}, | ||
], | ||
}) | ||
// test value displays on load | ||
const defaultVal = ref('TK Meowstersmith') | ||
const newVal = ref('') | ||
const formModel = ref<Record<string, any>>({ | ||
cat_name: defaultVal.value, | ||
}) | ||
// verify model updated reflects text input events | ||
const handleModelUpdated = (model: Record<string, any>, schema: string): void => { | ||
formModel.value[schema] = model | ||
} | ||
// test programmatic updates to model | ||
const setNewVal = (): void => { | ||
formModel.value.cat_name = newVal.value | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters