Socket
Socket
Sign inDemoInstall

js-laravel-validation

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-laravel-validation

Laravel style form validation for JavaScript


Version published
Weekly downloads
40
decreased by-18.37%
Maintainers
1
Weekly downloads
 
Created
Source

JS-Laravel-validation

Setup

Set custom messages:

    import { validate } from 'js-laravel-validation'
    
    validate.setCustomMessage('required', ({ key, value }) => `${key} field is required.`)

The parameter to your createMessage function will the same field object you supplied in your formData. Differences are it will have a key prop with the field name, and the validation prop will be an array of rules (with parameters if any)

E.g:

    validateForm({ 
        name: {
            value: "c mcg",
            validation: 'required|string',
            label: 'Full Name', //Custom property
        }
    })

will call the custom message function with

{
    key: 'name',
    validation: ['required', 'string'],
    value: "c mcg",
    label: 'Full Name',
}

Usage

Currently no dist is provided

  import { validateForm } from 'js-laravel-validation'
  
  const formData = {
    username: {
      value: 'test1',
      validation: 'required|string'
    },
    password: {
      value null,
      validation: 'required|string'
    }
  }
  
  const result = validateForm({
    formData,
    includeMessages: true,
  });
  
  if (result.errors) {
    Object.keys(result.errors).forEach(key => {
      const errors = result.errors[key];
      
      errors.forEach(error => {
        console.log(`invalid field field=${key} rule=${error.rule} messages=${error.message}`
      }
    }
  }

Keywords

FAQs

Package last updated on 13 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc