npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

esma-form

v0.0.15

Published

esma-form is a library for creating forms in Vue. The library allows you to create anything from simple forms to complex forms with conditional inputs and dynamic validations.

Downloads

2

Readme

Esma Form

esma-form is a library for creating forms in Vue. The library allows you to create anything from simple forms to complex forms with conditional inputs and dynamic validations.

Installation

Install the library using npm:

npm i esma-form

Basic Usage

Import style and component in main.js file

import '../node_modules/esma-form/dist/style.css'

import TheForm from '../node_modules/esma-form/dist/esma-form.mjs'

app.use(TheForm)

Then inside the component/page

<TheForm :form-data="formData" :form-rules="formRules"/>

You need to pass a JSON object to configure the form inputs. Here is an example of a basic input configuration:

dataInput: [
  {
    type: 'text',
    name: 'text',
    value: '',
    title: 'Text',
    placeholder: 'placeholder',
    notice: 'notice',
    class: 'group',
    show: true,
  },
]

Input Configuration

  • type: The type of input (e.g., text, checkbox, select).
  • name: The name attribute of the input.
  • title: The label for the input.
  • placeholder: The placeholder text for the input.
  • notice: A note that will appear below the input.
  • class: Optional CSS class for the input.
  • show: Determines whether the input is displayed. Useful for conditional inputs.

Form Submission

To handle form submission, you can trigger the sendData function which will pass the populated v-model by default.

<template>
  <TheForm @sendData="sendData" />
</template>

<script>
export default {
  methods: {
    sendData(data) {
      console.log(data);
    }
  }
}
</script>

# vue 3 

<script setup>
const sendData = (data) => {
    console.log(data)
}
</script>

Conditional Inputs

Checkbox Example

Conditional input configuration requires an activeValue that matches the name of the controlling input.

{
  type: 'checkbox',
  name: 'checkbox',
  value: 'test',
  class: 'checkbox',
  title: 'Checkbox',
  placeholder: 'placeholder',
  show: true,
}

Conditional input based on checkbox being checked:

{
  type: 'text',
  name: 'text2',
  value: '',
  title: 'Text2',
  placeholder: 'placeholder2',
  notice: 'notice2',
  class: 'group',
  activeValue: 'checkbox',
  show: false,
}

Radio or Select Example

{
  type: 'select',
  label: 'Select',
  name: 'select',
  activator: 'selectaltro',
  class: 'check',
  show: true,
  options: [
    {
      value: 'uno'
    },
    {
      value: 'due'
    },
    {
      value: 'selectaltro'
    },
  ]
}

Conditional input based on select option:

{
  type: 'text',
  name: 'text6',
  value: '',
  title: 'Text6',
  placeholder: 'placeholder9',
  notice: 'notice9',
  class: 'group',
  activeValue: 'selectaltro',
  show: false,
}

Validation Management

Validation is based on Vuelidate and is fully integrated.

To enable validation, create a validation object where the key matches the name of the input. For example:

{
  type: 'file',
  name: 'file',
  label: 'Scegli file',
  id: 'id',
  show: true,
}

Validation configuration:

file: { required },

Remember to add in your page/component the validation that you need to use

import {required, helpers, minLength} from '@vuelidate/validators'

For all validation rules, both conditional and general, refer to the Vuelidate documentation:

Vuelidate Documentation

Example Usage

Here is an example of how to use esma-form in your Vue component:



<template>
  <div>
    <TheForm :formData="formInputs" :formRules="formRules" @sendData="handleFormSubmit" />
  </div>
</template>

<script>
import { required } from '@vuelidate/validators';

export default {
  data() {
    return {
      formRules = {
         text: {
            required: helpers.withMessage('Valore obbligatorio', required),
            minLength: helpers.withMessage('Minimo 4 caratteri', minLength(4))
         },
         // email: {required, email},
         password: {required},
         radio: {required},
         checkbox: {required},
         select: {required},
         file: {required},

         checkbox2: {required},
         text6: {
            required: requiredIf(() => childModel.value.select === 'selectaltro'),
         }
      }
      dataInput: [
         {
            type: 'text',
            name: 'text',
            value: '',
            title: 'Text',
            placeholder: 'placeholder',
            notice: 'notice',
            class: "group",
            show: true,
         },
         {
            type: 'email',
            name: 'email',
            value: '',
            title: 'Email',
            placeholder: '[email protected]',
            notice: 'notice',
            class: 'group',
            show: true,
         },
         {
            type: 'email',
            name: 'email2',
            value: '',
            title: 'Email2',
            placeholder: '[email protected]',
            notice: 'notice',
            class: 'group',
            show: true,
         },
         {
            type: 'password',
            name: 'password',
            value: '',
            title: 'Password',
            placeholder: 'placeholder',
            notice: 'notice',
            class: 'group',
            show: true,
         },
         {
            type: 'radio',
            label: 'radio',
            name: 'radio',
            title: 'input radio',
            class: 'check',
            activator: 'altro',
            show: true,
            options: [
               {
                  value: 'uno',
                  type: 'radio',
                  name: 'radio',
                  class: 'check',
                  title: 'Radio',
               },
               {
                  value: 'due',
                  type: 'radio',
                  name: 'radio',
                  class: 'check',
                  title: 'Radio',
               },
               {
                  value: 'altro',
                  type: 'radio',
                  name: 'radio',
                  class: 'check',
                  title: 'Altro',
               },
            ]
         },
         {
            type: 'text',
            name: 'text5',
            value: '',
            title: 'Text5',
            placeholder: 'placeholder3',
            notice: 'notice3',
            class: "group",
            activeValue: 'altro',
            show: false,
         },
         {
            type: 'checkbox',
            name: 'checkbox4',
            value: 'test',
            class: 'checkbox',
            title: 'Checkbox 4',
            placeholder: 'placeholder',
            show: true,
         },
         {
            type: 'checkbox',
            name: 'checkbox',
            value: 'test',
            class: 'checkbox',
            title: 'Checkbox',
            placeholder: 'placeholder',
            show: true,
         },
         {
            type: 'text',
            name: 'text2',
            value: '',
            title: 'Text2',
            placeholder: 'placeholder2',
            notice: 'notice2',
            class: "group",
            activeValue: 'checkbox',
            show: false,
         },
         {
            type: 'checkbox',
            name: 'checkbox2',
            value: 'test',
            class: 'checkbox',
            title: 'Checkbox2',
            placeholder: 'placeholder',
            show: true,
         },
         {
            type: 'text',
            name: 'text3',
            value: '',
            title: 'Text3',
            placeholder: 'placeholder3',
            notice: 'notice3',
            class: "group",
            activeValue: 'checkbox2',
            show: false,
         },
         {
            type: 'select',
            label: 'Select',
            name: 'select',
            activator: 'selectaltro',
            class: 'check',
            show: true,
            options: [
               {
                  value: 'uno'
               },
               {
                  value: 'due'
               },
               {
                  value: 'selectaltro'
               },
            ]
         },
         {
            type: 'text',
            name: 'text6',
            value: '',
            title: 'Text6',
            placeholder: 'placeholder9',
            notice: 'notice9',
            class: "group",
            activeValue: 'selectaltro',
            show: false,
         },
         {
            type: 'file',
            name: 'file',
            label: 'Scegli file',
            id: 'id',
            show: true,
         },
      ],
      }
    };
  },
  methods: {
    handleFormSubmit(data) {
      console.log(data);
    },
  },
};
</script>