Code Monkey home page Code Monkey logo

Comments (6)

deepsweet avatar deepsweet commented on June 9, 2024 1

@tirli done, [email protected]

from neoform.

deepsweet avatar deepsweet commented on June 9, 2024

I got the idea and the issue... I'm not sure which types we should pass in validator, it feels more like NeoForm internals you shouldn't rely on. I'm thinking more about propagating a form-wide prop like isSubmitting so you can choose which validator to use from outside.

const userNameValidator = (isSubmitting) => (value) => {
  return isSubmitting ?
         Promise.resolve('valid on submit') :
         Promise.resolve('valid on some other event')
}

// ...

<MyInput name="user.name" validator={userNameValidator(isSubmitting)} />

I'm not quite sure that something like this will work because we need to render first with isSubmitting, receive updated validator function and only after that validate the form, but I like the idea of making it more abstract and flexible in any way. What do you think? Or do you have an idea on how to pass those validator "types"?

from neoform.

deepsweet avatar deepsweet commented on June 9, 2024

Btw, we can internally call validator with field or form "types", right from formValidation:

validateField(name) {
  // ...
  validator(value, 'field')
  // ...
}

validateForm(successHandler, errorHandler) {
  // ...
  return validator(value, 'form')
  // ...
}

It's more about source or reason of validation than a type, but it's still the easiest fix.

from neoform.

tirli avatar tirli commented on June 9, 2024

It seems like the first one wouldn't work because there is still only one validator. So closure wouldn't help.

The second approach is better, but it wouldn't work if I need to detect if it blur or change or some other event.

I think that we can add an argument to validate method. Most of the cases it's used like
<input onChange={validate} /> so it will be getting an event. So we can use event.type inside or if it was called directly by user he should provide a { type: 'myCustomAction'} of just nothing. What is more, the same thing we can make with submitting. Add it as a custom type.

from neoform.

deepsweet avatar deepsweet commented on June 9, 2024

Sorry I still don't have much time to work on NeoForm :( Your PR is merged, but I'm going to release it together with #11

from neoform.

tirli avatar tirli commented on June 9, 2024

@deepsweet If it possible, can you please release it before? So it wouldn't be blocking me and you won't need to fix #11 as soon as possible and can fix it when you'll have time

from neoform.

Related Issues (9)

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.