@felte/core
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -15,2 +15,3 @@ import { isFormControl, isElement } from './packages/common/dist/esm/utils/typeGuards.js'; | ||
let control; | ||
let onReset; | ||
if (typeof nameOrConfig === 'string') { | ||
@@ -20,2 +21,3 @@ name = nameOrConfig; | ||
touchOnChange = (_a = config === null || config === void 0 ? void 0 : config.touchOnChange) !== null && _a !== void 0 ? _a : false; | ||
onReset = config === null || config === void 0 ? void 0 : config.onReset; | ||
} | ||
@@ -26,2 +28,3 @@ else { | ||
touchOnChange = (_b = nameOrConfig.touchOnChange) !== null && _b !== void 0 ? _b : false; | ||
onReset = nameOrConfig === null || nameOrConfig === void 0 ? void 0 : nameOrConfig.onReset; | ||
} | ||
@@ -52,5 +55,12 @@ function dispatchEvent(eventType, value) { | ||
} | ||
function handleReset(e) { | ||
if (!onReset) | ||
return; | ||
setControlValue(control, defaultValue); | ||
onReset(e); | ||
} | ||
function field(node) { | ||
fieldNode = node; | ||
let observer; | ||
let formElement; | ||
if (isFormControl(node)) { | ||
@@ -81,2 +91,4 @@ control = node; | ||
observer.observe(control, observerConfig); | ||
formElement = control.closest('form'); | ||
formElement === null || formElement === void 0 ? void 0 : formElement.addEventListener('reset', handleReset); | ||
}); | ||
@@ -86,2 +98,3 @@ return { | ||
observer === null || observer === void 0 ? void 0 : observer.disconnect(); | ||
formElement === null || formElement === void 0 ? void 0 : formElement.removeEventListener('reset', handleReset); | ||
}, | ||
@@ -88,0 +101,0 @@ }; |
@@ -6,2 +6,3 @@ import { FieldValue } from '@felte/common'; | ||
defaultValue?: FieldValue; | ||
onReset?(e: ResetEvent): void; | ||
}; | ||
@@ -16,2 +17,5 @@ type Field = { | ||
}; | ||
type ResetEvent = Event & { | ||
target: HTMLFormElement; | ||
}; | ||
declare function createField(name: string, config?: Omit<FieldConfig, 'name'>): Field; | ||
@@ -18,0 +22,0 @@ declare function createField(config: FieldConfig): Field; |
@@ -20,2 +20,3 @@ import { Readable } from "svelte/store"; | ||
defaultValue?: FieldValue; | ||
onReset?(e: ResetEvent): void; | ||
}; | ||
@@ -30,2 +31,5 @@ type Field = { | ||
}; | ||
type ResetEvent = Event & { | ||
target: HTMLFormElement; | ||
}; | ||
declare function createField(name: string, config?: Omit<FieldConfig, "name">): Field; | ||
@@ -32,0 +36,0 @@ declare function createField(config: FieldConfig): Field; |
{ | ||
"name": "@felte/core", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Core utility for Felte's integration with front-end frameworks", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs/index.cjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
450100
3987