1.5.1 • Published 4 years ago
@vdegenne/mwc-forms-util v1.5.1
@vdegenne/mwc-forms-util
A set of convenient methods for manipulating forms using @material elements.
Work still in Progress Please don't hesitate to make some Pull Request to improve this module.
Installation
npm i @vdegenne/mwc-forms-util
Then in your code
import { ... } from '@vdegenne/mwc-forms-util';
(Note: You can use this same line for TypeScript project, the typings are already included in the package).
You can also include this package directly in your html
<script type="module" src="/node_modules/@vdegenne/mwc-forms-util/util.js"></script>
If you have a node module path resolver server then you can just type
<script type="module" src="@vdegenne/mwc-forms-util"></script>
Usage
validateForm
if (!validateForm(formElement)) {
console.log('something went wrong');
}
else {
// continue
}
This function will also report the validity and the user-defined helper will be triggered (e.g. mwc-textfield
will becomes red if it was required but the field is empty).
serializeForm
Digests an object {name: value}
representing the form.
const object = serializeForm(formElement);
fillForm
const object = {
name: 'Martin',
age: 32,
phone: '123-456
};
fillForm(formElement, object);
resetForm(formElement)
Resets the form element.