Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: array validation and custom messages #19

Merged
merged 4 commits into from
Aug 23, 2017

Conversation

Idered
Copy link
Contributor

@Idered Idered commented Aug 22, 2017

const { validate } = require('../src')

export default () => {
  const data = {
    firstName: 'John',
    lastName: 'Doe',
    age: [16, 24],
    gender: 'male'
  }

  const rules = {
    firstName: 'required|min:2',
    lastName: 'required|min:2',
    'age.*': 'required|numeric|min:18'
  }

  const messages = {
    'min': 'Field value must be at least :min',
    'firstName.required': 'Please pass your first name', // This have higher priority than custom 'required' message
    'required': 'Field is required',
    'age.*': {
      min: 'Every age must be at least :min'
    }
  }

  validate(data, rules, messages)
    .then(console.log)
    .catch(console.log)
}

@Idered Idered self-assigned this Aug 22, 2017
@Idered Idered requested review from mkucharz and Flixow August 22, 2017 16:16
@codecov-io
Copy link

Codecov Report

Merging #19 into devel will decrease coverage by 1.67%.
The diff coverage is 68.96%.

@@            Coverage Diff             @@
##            devel      #19      +/-   ##
==========================================
- Coverage   94.56%   92.88%   -1.68%     
==========================================
  Files           5        5              
  Lines         570      562       -8     
==========================================
- Hits          539      522      -17     
- Misses         31       40       +9

@eyedea-io eyedea-io deleted a comment from codecov-io Aug 22, 2017
src/index.js Outdated

attribute = this.isWildcard(attribute) ? `${attribute}.*` : attribute

console.log(this.customMEssages, attribute, lowerRule)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unnecessary

@codecov-io
Copy link

Codecov Report

Merging #19 into devel will decrease coverage by 1.67%.
The diff coverage is 68.96%.

@@            Coverage Diff             @@
##            devel      #19      +/-   ##
==========================================
- Coverage   94.56%   92.88%   -1.68%     
==========================================
  Files           5        5              
  Lines         570      562       -8     
==========================================
- Hits          539      522      -17     
- Misses         31       40       +9

@Idered Idered merged commit ae9ed5e into devel Aug 23, 2017
@Idered Idered deleted the feat/array-validation-and-custom-messages branch August 23, 2017 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants