A package based on Sweetalert2. that provides highly customizable promised-based popup forms, with features like form advanced validation, optional http request handling, multiple-steps, and many more !
Key Features •
How To Use •
Documentation & Live Examples •
Improvements roadmap •
Credits
Key Features
- Grid-based templating - Create your layouts
- High depth of forms layout customisation, based on css grid
- A lot of input types supported
- List of supported input types : text, textarea, email, password, number, select, radio, checkbox, file, week, month, time, datetime-local, date
- Custom input types coming soon (Data-table select, and many others)
- Support advanced customisable validation
- Includes basic validators : required, email, phone number. Other validators comming soon
- Custom validators : Define your own validators and apply them to any field. Promise-based, supports async
- Dark/Light mode
- Supports multiple steps forms
- Provide feedback functions that allow you to show success / error feedback after processing form content
- 100% Responsive
- Works with VanillaJS, and any front-end javascript framework (Vue, React, Angular, ..)
How To Use
$ npm install --save @sweetalert2/sweetforms
import { SimpleForm, SteppedForm } from "@sweetalert2/sweetforms";
SimpleForm({
themeConfig: {
darkMode: false,
maxHeight: "65vh",
},
itemsByLine: 2,
title: "Sign in",
customValidators: {
checkEmailAvailable: async ({ field, value, validate }) => {
let isAvailable = true
if (isAvailable) validate({ isValid: true });
else
validate({
isValid: false,
message: `This email address is not available`,
force: true,
});
},
},
fields: [
{
label: "Email address",
key: "email",
type: "text",
value: "",
placeholder: "john.doe@mail.com",
validation: ["required", "email"],
customValidation: ["checkEmailAvailable"],
fullWidth: true,
},
{
confirmPassword: true,
label: "Password",
key: "password",
type: "password",
value: "",
placeholder: "••••••••••",
validation: ["required"],
},
{
label: "Country",
key: "country",
type: "select",
value: "",
options: [
{ label: "Select a country", value: "" },
...[
"France",
"Spain",
"England",
"Italy",
"United States",
"Canada",
"Japan",
].map((opt) => {
return { label: opt, value: opt.toLowerCase() };
}),
],
validation: ["required"],
},
{
label: "Upload an avatar",
type: "file",
key: "avatar",
value: "",
validation: ["required"],
attributes: {
accept: "image/png, image/jpeg",
},
},
{
label: "Gender",
type: "radio",
key: "gender",
validation: ["required"],
options: [
{ label: "Male", value: "m" },
{ label: "Female", value: "f" },
],
fullWidth: true,
},
],
}).then((result) => {
const { success, formData, ShowFeedback } = result;
ShowFeedback({
success: true,
title: "Form completed !",
text: "",
timer: 3000,
});
});
Documentation and live examples
Improvements roadmap
Credits
This package is entirely based on Sweetalert2, and its promise-based notification system.
You want to improve this library ? Or any ideas of improvements ?
This project is 100 % open-source, do not hesitate to give feedback on the library, ask for new features or even make a pull request. Any participation is welcomed.
License
MIT
GitHub @ChronicStone ·