A form management library for SolidJS that is very lightweight and simple!

Overview

solform

A form management library for SolidJS that is very lightweight and simple!

npm GitHub Repo stars

Why solform

  • Very easy, fast, lightweight and powerful!
  • It has built-in validation.
  • You can easily customize it!
  • Full type support

Create form

// Simplest
import { createForm } from "solform";

function App() {
    const { values, register } = createForm<{name: string}>();

    return <input {...register("name")}>;
}
// Next Level
import { createForm, requiredValidator, emailValidator } from "solform";

function App() {
    const { values, register, submit, errors } = createForm<{email: string, count: number }>({
        validators: {
            count: requiredValidator("Count is required"),
            email: [requiredValidator("This field is required"), emailValidator("Value should be email!")]
        },
        onSubmit: (values) => {
            // type safe values
            console.log(values);
        }
    });

    return (
        <div>
            <input {...register("email")} type="email">
            {errors.email && <p class="error">{errors.email}</p>}

            {/* When you read count, it will be converted to number */}
            <input {...register("count")} type="number">
            <button onClick={submit}>Submit</button>
        <div/>)
}
// Full
import { createForm, requiredValidator, emailValidator } from "solform";

function App() {
const { values, register, submit, loading, getAllValues, getValue, setValue, errors, watch } = createForm<{email: string, count: number }>({
    initialValues: {
        count: 0
    },
    validators: {
        count: requiredValidator("Count is required"),
        email: [requiredValidator("This field is required"), emailValidator("Value should be email!")]
    },
    onSubmit: async (values) => {
        await sleep(2000); // it will automatically set loading to true
        console.log(values);
        // loading is false again
    }
});

    // will call the given function whenever the count changes
    watch("count", (updatedCount) => {
        console.log(updatedCount);
    })

return (
        <div>
            <input {...register("email")} type="email">
            {errors.email && <p class="error">{errors.email}</p>}
            {/* When you read count, it will be converted to number */}
            <input {...register("count")} type="number">
            <button onClick={submit} disabled={loading}>{loading ? "Loading..." : "Submit"}</button>
        <div>
 )
}

Built-in validators

  • minLengthValidator(minLength, errorMessage)
  • maxLengthValidator(maxLength, errorMessage)
  • requiredValidator(errorMessage)
  • emailValidator(errorMessage)

Creating new validators

const minimumNumberValidator =
  (minNumber: number, errorMessage: string): SolFormValidator<number> =>
  (val) =>
    val < minNumber ? errorMessage : undefined;

Tactics

  • Always use watch inside a component, because it will call onMount and onCleanup.
  • More soon...

What is next?

  • Support for more fields, such as radio group
  • Validate on change option.

How to contribute?

  • Get a fork of this package, do your changes and create a pull request.
  • Found a bug? create an issue.
Comments
  • set same `validators` warnings for multiple values?

    set same `validators` warnings for multiple values?

    like how to do this?

    validators: {
            email: [
              requiredValidator("This field is required"),
              emailValidator("Value should be email!"),
            ],
            name,id,captcha:[
              requiredValidator("This field is required")
            ],
    

    can do currently:

    const { register, submit, loading, getAllValues, getValue, setValue, errors, watch } =
        createForm<{ email: string; name: string, password: string, id: string, captcha: boolean }>({
          initialValues: {
          },
          validators: {
            email: [
              requiredValidator("This field is required"),
              emailValidator("Value should be email!"),
            ],
            name: [
              requiredValidator("This field is required"),
            ],
            id: [
              requiredValidator("This field is required"),
            ],
            password: [
              requiredValidator("This field is required"),
            ],
            captcha: [
              requiredValidator("Solving captcha is required"),
            ]
          },
    
    opened by debpalash 11
  • Alter type definition for SolFormElement to include HTMLTextAreaElement

    Alter type definition for SolFormElement to include HTMLTextAreaElement

    Typescript compiler currently throws an error while using solform with the textarea tag. This fix simply requires to change the type definition of the SolFormElement as the actual functionality does not change.

    Current

    export declare type SolFormElement = HTMLInputElement | HTMLSelectElement;
    

    Proposed change

    export declare type SolFormElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
    
    opened by shodevacc 2
  • Alter type definition for SolFormElement to include HTMLTextAreaElement

    Alter type definition for SolFormElement to include HTMLTextAreaElement

    Typescript compiler currently throws an error while using solform with the textarea tag. This fix simply requires to change the type definition of the SolFormElement as the actual functionality does not change.

    opened by shodevacc 1
  • const { values, .. } Property 'values' does not exist on type?

    const { values, .. } Property 'values' does not exist on type?

    Can you example out how to use values?

    const values: any
    'values' is declared but its value is never read.ts(6133)
    Property 'values' does not exist on type '{ register: (key: "email" | "count") => { ref: (ref: SolFormElement) => SolFormElement; name: "email" | "count"; }; submit: (event?: Event | undefined) => Promise<...>; ... 5 more ...; getAllValues: () => { ...; }; }'.ts(2339)
    
    opened by debpalash 1
  • Radio Group Support

    Radio Group Support

    Hi, I'm using your library (thank you 🙏), and I'm wondering what is lacking currently in terms of support for radio groups in forms? I would be willing to contribute a PR to add support.

    opened by mosheduminer 1
Owner
Okan YILDIRIM
I'm Okan, a Mobile/Web Developer. Check my website for further information and contact.
Okan YILDIRIM
The LMS (Life Management System) is a free tool for personal knowledge management and goal management based on Obsidian.md.

README Documentation | 中文帮助 The LMS (Life Management System) is a tool for personal knowledge management and goal management based on Obsidian.md. It

null 27 Dec 21, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
An exercise in building a very minimal (and very stupid) in-memory SQL-like database for educational purposes.

Stupid Database This is an exercise in building a very minimal (and very stupid) in-memory SQL-like database for educational purposes. None of this co

Fabio Akita 196 Dec 20, 2022
A Very Good Documentation Site created by the Very Good Ventures Team 🦄

Very Good Docs Site Developed with ?? by Very Good Ventures ?? A Very Good Docs Site created by the Very Good Ventures Team. Generated by the Very Goo

Very Good Open Source 8 Nov 2, 2022
This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

HtmlFormApp Overview This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreads

Kanshi TANAIKE 18 Oct 23, 2022
A lightweight SolidJS component for building interactive node-based diagrams and graphs.

Convert Your Ideas To Graphs With Solid Graph! Solid Graph A lightweight and minimal Solid component for building interactive graphs and node-based ed

Ali Sal 26 Dec 8, 2022
A lightweight SolidJS component for building interactive node-based diagrams and graphs.

Convert Your Ideas To A Simple And Excitig Journay With Odysea! Odysea A lightweight and minimal Solid component for building interactive graphs and n

Ali Sal 21 Aug 15, 2022
A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again.

form-storage A JavaScript library stores the form-data to the localstorage so you don't have to fill the form again. Installation via npm npm install

appleple 159 Dec 10, 2022
FormGear is a framework engine for dynamic form creation and complex form processing and validation for data collection.

FormGear is a framework engine for dynamic form creation and complex form processing and validation for data collection. It is designed to work across

Ignatius Aditya Setyadi 91 Dec 27, 2022
The Frontend of Escobar's Inventory Management System, Employee Management System, Ordering System, and Income & Expense System

Usage Create an App # with npx $ npx create-nextron-app my-app --example with-javascript # with yarn $ yarn create nextron-app my-app --example with-

Viver Bungag 4 Jan 2, 2023
Auth-Form-Design - Beautiful Auth Form Designed using React 🥰.

?? Auth Form Design ?? Features 1. Check Your Password Strength 2. Can Use Suggested Password 3. Enjoy Responsive Design Getting Started with Create R

Samarpan Dasgupta 2 Dec 24, 2022
Gatsby-Formik-contact-form-with-backend-panel - Full working contact form with backend GUI panel.

Gatsby minimal starter ?? Quick start Create a Gatsby site. Use the Gatsby CLI to create a new site, specifying the minimal starter. # create a new Ga

Bart 1 Jan 2, 2022
Form To CSS - jQuery-Plugin form to CSS generator

Create your own CSS generator with the form to css generator Builder plugin. Can be usefull to create your own css builder or a Wordpress plugin or any kind of apps you need a real time css generator. For example, you can create a button generator

Gino 4 Sep 26, 2021
Simple and lightweight form validation for Svelte with no dependencies.

Svelidate Simple and lightweight form validation for Svelte with no dependencies Installation // npm npm install svelidate // yarn yarn add svelidate

null 28 Dec 28, 2022
A library of high-quality primitives that help you build accessible user interfaces with SolidJS.

Solid Aria A library of high-quality primitives that help you build accessible user interfaces with SolidJS. Primitives @solid-aria/primitives - Expor

SolidJS Community 205 Jan 7, 2023
DateTimePickerComponent is a very lightweight and dependency-free web component written in pure JavaScript

DateTimePickerComponent Description DateTimePickerComponent is a very lightweight (just over 20KB) and dependency-free web component written in pure J

null 14 Dec 24, 2022
EggyJS is a Javascript micro Library for simple, lightweight toast popups focused on being dependency-less, lightweight, quick and efficient.

EggyJS EggyJS is a Javascript micro Library for simple, lightweight toast popups. The goal of this library was to create something that meets the foll

Sam 10 Jan 8, 2023