Coder Social home page Coder Social logo

react-simple-form-validator's People

Contributors

perscrew avatar raederdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-simple-form-validator's Issues

[Feature Request]: Add custom validation function

Add custom validation function such that users can be able to provide their custom field validator function.

Example

const { } = useValidation({
    fieldsRules: {
      name: {
        validator: (value: string): boolean => {
            return boolean;
         },
      },
    },
    state: { name },
  });

Multiple Validation

I am trying to incorporate multiple validations for a 'multi screen form'. As my form is dynamic, the validation needs to be written for all fields within the same file (unless there is a recommended way to handle this separately).

For example:

useValidation written

Form1
Form2 appears after form1 is validated

Is there a solution to this?

Thanks

Bug on Display Error Message on Customize Rules and Customize Message

When i tried using customize rules, i guess, i need to add customize message for the new rule i created. Otherwise, when validation failed, the app will show error:

    const { isFieldInError, getErrorsInField, isFormValid } = useValidation({
      fieldsRules: {
        name: { required: true, minlength: 5, maxlength: 30,  cusR: 'aaa'},
      },
      rules: {
        ...defaultRules,
        cusR: (format: string, value) => {
          return value.indexOf(format) > -1;
        }
      },
      state: { name },
    })

TypeError: Cannot read properties of undefined (reading 'replace')

This happened on line 93 on file: services/validator-service.js,
Because no match customized rule name in the default messages map appearantly.

After i add cusomized message (I know i need to add other), the validation failure message will be : "name NaN invalid"

    const { isFieldInError, getErrorsInField, isFormValid } = useValidation({
      fieldsRules: {
        name: { required: true, minlength: 5, maxlength: 30,  cusR: 'aaa'},
      },
      rules: {
        ...defaultRules,
        cusR: (format: string, value) => {
          return value.indexOf(format) > -1;
        }
      },
      messages: {
        ...defaultMessages,
        en: {...defaultMessages.en, cusR: "{0} {1} invalid"}
      },
      state: { name },
    })

I found bug on line 91 on File: services/validator-service.js,

evaluate +value will be 'NaN', if value is undefined.

(function()
{
    'use strict';
    console.log(+ undefined)
}());

// NaN

I think more condition check need to be add on this part.

I don't know whether my explaination makes sense or not. if not , i am sorry about it.

Overall, this is a greate library, I am glad i found it and thank you for your sharing.
If need more information or other query, please let me know. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.