Skip to content
This repository was archived by the owner on Apr 9, 2025. It is now read-only.

Commit 59922fb

Browse files
authored
Merge pull request #49 from dbssman/bugfix/44-native-element-refresh-when-value-is-not-set-due-to-binding-issues
♻️ Trigger native element patch
2 parents e2d7a68 + ea34dd6 commit 59922fb

File tree

8 files changed

+115
-3
lines changed

8 files changed

+115
-3
lines changed

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@
6161
"vitest": "^0.26.1",
6262
"vue-tsc": "^1.0.9"
6363
}
64-
}
64+
}

Diff for: playground/App.vue

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<template>
2+
<h2>Playground</h2>
3+
<input v-bind="register('playground')">
4+
</template>
5+
6+
<script setup lang="ts">
7+
import { useFormHandler } from '../src/index'
8+
9+
const { register } = useFormHandler();
10+
11+
</script>
12+
13+
<style>
14+
* {
15+
box-sizing: border-box;
16+
margin: 0;
17+
padding: 0;
18+
text-align: center;
19+
}
20+
21+
body {
22+
display: flex;
23+
align-items: center;
24+
justify-content: center;
25+
background-color: #242424;
26+
font-family: 'Open Sans', sans-serif;
27+
font-size: 16px;
28+
color: #42B883;
29+
min-height: 100vh;
30+
}
31+
32+
h2 {
33+
margin: 1em;
34+
}
35+
36+
label {
37+
display: block;
38+
}
39+
40+
form {
41+
display: flex;
42+
flex-direction: column;
43+
align-items: flex-end;
44+
gap: 1em;
45+
}
46+
47+
input,
48+
select,
49+
textarea,
50+
button {
51+
border: none;
52+
border-radius: 5px;
53+
width: 300px;
54+
min-height: 40px;
55+
background-color: #35495E;
56+
color: #42B883;
57+
}
58+
59+
button {
60+
background-color: #42B883;
61+
color: #35495E;
62+
cursor: pointer;
63+
text-transform: uppercase;
64+
font-weight: bold;
65+
}
66+
</style>

Diff for: playground/index.html

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
8+
<title>Playground</title>
9+
</head>
10+
11+
<body>
12+
<div id="app"></div>
13+
<script type="module" src="/main.ts"></script>
14+
</body>
15+
16+
</html>

Diff for: playground/main.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createApp } from 'vue'
2+
import App from './App.vue'
3+
4+
const app = createApp(App)
5+
6+
app.mount('#app')

Diff for: playground/public/favicon.svg

+13
Loading

Diff for: playground/vite-env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />

Diff for: src/useFormHandler.ts

+9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import { reactive, readonly, unref, watch } from '@vue/runtime-core'
2828
import { isEqual } from 'lodash-es'
2929
import { getNativeFieldValue, validateField, validateForm, getDefaultFieldValue, refFn, transformValidations } from './logic';
30+
import { isNativeControl } from './utils';
3031

3132
export const initialState = () => ({
3233
touched: {},
@@ -175,6 +176,14 @@ export const useFormHandler: UseFormHandler = ({
175176
}))) {
176177
values[name] = value
177178
setDirty(name, !isEqual(value, _getInitial(name)))
179+
return
180+
}
181+
if (isNativeControl((Array.isArray(_refs[name].ref)
182+
? (_refs[name].ref as FieldReference[])[0]
183+
: _refs[name].ref) as HTMLInputElement)) {
184+
const prev = values[name]
185+
values[name] = undefined
186+
values[name] = prev
178187
}
179188
}
180189

Diff for: vite.config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import vue from '@vitejs/plugin-vue'
66
import dts from 'vite-plugin-dts'
77

88
// https://vitejs.dev/config/
9-
export default defineConfig({
9+
export default defineConfig(({ mode }) => ({
1010
define: {
1111
'import.meta.vitest': false,
1212
},
13+
root: mode === 'development' ? 'playground' : '',
1314
test: {
1415
includeSource: ['test/*'],
1516
environment: 'happy-dom',
@@ -39,4 +40,4 @@ export default defineConfig({
3940
insertTypesEntry: true,
4041
}),
4142
]
42-
})
43+
}))

0 commit comments

Comments
 (0)