Releases: FThompson/FormPersistence.js
New options: include and exclude elements with filter functions
Added includeFilter
and excludeFilter
options to all functions:
includeFilter
Define a whitelist filter function that inputs an element and outputs a Boolean. The element is included if the function returns true. This option must be a function that accepts an element parameter. This filter does not apply to any elements specially handled invalueFunctions
.excludeFilter
Define a blacklist filter function that inputs an element and outputs a Boolean. The element is excluded if the function returns true. This option must be a function that accepts an element parameter. This filter does not apply to any elements specially handled in valueFunctions. Exclusions take precedence over inclusions.
For example, the following option excludes hidden fields:
FormPersistence.persist(form, { excludeFilter: element => element.type === 'hidden' });
Alternatively, the following option includes all non-hidden fields:
FormPersistence.persist(form, { includeFilter: element => element.type !== 'hidden' });
Fixed checkbox array bug
Fixed an issue where checkbox arrays were not serialized correctly (#12).
Syntax fix for Babel 7 compilation
Minor fix for Babel 7 compilation, see #8.
Bugfix for setting nameless input values to undefined
Previously, a bug would occur when persisting a form with nameless input fields where upon load the field's value would be set to undefined. This release fixes that bug.
New options: include and exclude elements by name
Added include
and exclude
options to all functions:
include
Define a whitelist of input names to be included during serialization. This option must be an array of strings.exclude
Define a blacklist of input names to be excluded during serialization. This option must be an array of strings.
Fixed a bug where non-data-persistence elements like <button>
were serialized as a blank array.
Use form.elements instead of custom form element getter
Use form.elements
instead of custom form element getter. This change simplifies the code and may improve performance by avoiding DOM queries.
Support id-less forms, IE, Edge<18, skipExternal and uuid options
This release is highlighted by new configuration options, bug fixes, and breaking changes for defining options.
- Use of an
options
object parameter to customize behavior, replacing the series of parameters on functions that had options. This change makes the library more future proof for adding additional options easily. This change breaks backwards compatibility. - Support id-less forms. Specify
uuid
in options or an error will be thrown. Theuuid
can also be set for forms that have an id. - Support for IE and Edge < 18. Library now uses custom form serialization instead of FormData which is not supported in these browsers.
- The
skipExternal
option can be set totrue
in order to skip form elements defined outside the form hierarchy withform='form-id'
attributes. The entire document rather than just the form, must be searched for these external elements, so setting this option can improve performance on large pages.
Updated npm readme and removed extra React code
No functional changes in this release.
Created and published to npm
FormPersistence.js is now available on npm as form-persistence
.
npm install form-persistence
Additionally added an example using React.
Fixed event detection bug on iOS Safari
Safari in iOS does not support the beforeunload
event that FormPersistence previously relied on to know when to save form data to storage. In this release, the library additionally listens to unload
events as a failsafe and removes the unload
event listener if the beforeunload
event successfully fires first.
If edge cases are discovered where neither beforeunload
nor unload
are fired, the pagehide
event may be useful.