Skip to content

Commit

Permalink
Merge pull request #48 from dbssman/bugfix/47-native-handler-overwrit…
Browse files Browse the repository at this point in the history
…es-value-of-custom-components

🔨 Fix custom element detection
  • Loading branch information
dbssman authored Feb 7, 2023
2 parents 7369507 + 138efe8 commit 6f05898
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-form-handler",
"version": "0.2.4",
"version": "0.2.5",
"type": "module",
"license": "MIT",
"author": "Dennis R. Bosmans",
Expand Down
2 changes: 1 addition & 1 deletion src/logic/refFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default (name: string, _refs: Refs, values: any) => (fieldRef: any) => {
delete _refs[name]
return
}
if (!fieldRef.nodeName || !isNativeControl(fieldRef)) {
if (fieldRef.$el || !fieldRef.nodeName || !isNativeControl(fieldRef)) {
//TODO: Correctly type this in order to expect a fixed data structure
_refs[name].ref = {
type: 'custom'
Expand Down
10 changes: 8 additions & 2 deletions src/useFormHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
IsValidForm,
Refs,
ValidationsConfiguration,
Unregister
Unregister,
FieldReference
} from './types';
import { reactive, readonly, unref, watch } from '@vue/runtime-core'
import { isEqual } from 'lodash-es'
Expand Down Expand Up @@ -236,7 +237,12 @@ export const useFormHandler: UseFormHandler = ({
isTouched: !!formState.touched[name],
}),
...(native !== false && {
onChange: async () => await handleChange(name, getNativeFieldValue(_refs[name].ref)),
onChange: async () => {
if (!_refs[name].ref || (_refs[name].ref as FieldReference).type === 'custom') {
return
}
await handleChange(name, getNativeFieldValue(_refs[name].ref))
},
}),
...(useNativeValidation && {
...({
Expand Down

1 comment on commit 6f05898

@vercel
Copy link

@vercel vercel bot commented on 6f05898 Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.