@formsignals/form-core
v0.4.5
Published
Core package for Signal Form including the form state and validation logic as well as the api
Downloads
1,775
Readme
The core library for managing forms with Preact Signals.
Features
- TypeScript - Written in TypeScript with full type support for optimal DX.
- Reactivity - Reactivity without abstractions thanks to Preact Signals.
- Validation - Built-in validation support, including adapters for validation schema libraries.
- Transformations - Transform values for the specific needs of your input fields.
- Field Groups - Group fields together to manage parts of a form independently.
- Async Data - Easily manage async initialisation, validation and submission.
- Arrays + Dynamic Objects - Utilize arrays and dynamic objects within your forms.
Install
npm install @formsignals/form-core
If you have not installed signals, you will need to install it as well:
npm install @preact/signals-core
Quickstart
Create a new form instance:
const form = new FormLogic({
defaultValues: {
name: '',
email: '',
},
});
Then get a field instance from the form and configure it:
const nameField = form.getOrCreateField('name', {
validate: (value) => {
if (!value) {
return 'Name is required';
}
},
});
Now you can interact with the field:
nameField.handleChange('John Smith');
You can also access the underlying signal directly:
const nameLength = computed(() => nameField.value.length);