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

driver / form / validator #221

Open
fabienjuif opened this issue Sep 5, 2018 · 3 comments
Open

driver / form / validator #221

fabienjuif opened this issue Sep 5, 2018 · 3 comments
Labels
feature help wanted Extra attention is needed

Comments

@fabienjuif
Copy link
Member

fabienjuif commented Sep 5, 2018

  • add metadata store
  • add a validator function to get (as a callback)
    • if the function is here: call it + test classic HTML5 like required and pattern
    • if the function is not here, just test classic HTML5 like required and pattern
    • if false, test nothing

get should returns

  • undefined if tests failed, and errors store is filled with errors
  • values if tests are ok
  // test inputs (required/pattern)
  const loginValues = form('login').get()

  //  test input "name" (required/pattern)
  const name = form('login').get('name')

  // test inputs (required/pattern + validator)
  const loginValues = form('login').get(values => values.name.length > 10)

  //  test input "name" (required/pattern + validator)
  const name = form('login').get('name', value => value.length > 10)

  // test inputs (validator only)
  const loginValues = form('login').get(values => values.name.length > 10, false)

  //  test input "name" (validator only)
  const name = form('login').get('name', value => value.length > 10, false)

to set metadata:

form('login').setMetadata({ name: { required: true, pattern: /[a-b]+/ } })
@fabienjuif
Copy link
Member Author

fabienjuif commented Sep 5, 2018

or get.validate ? get alone will not do validation ?

const loginValues = form('login').get()
const loginValues = form('login').get.validate()
const name = form('login').get.validate('name') // feel odd

@fabienjuif fabienjuif self-assigned this Sep 5, 2018
@guillaumecrespel
Copy link
Member

I think we can pass the validator on second function props .

  const loginValues = form('login').get(([value, validator]) => {})
  const loginValues = form('login').get('name', (value, validator) => {})

@fabienjuif
Copy link
Member Author

fabienjuif commented Sep 6, 2018

with middleware support

  // test inputs (required/pattern)
  const loginValues = form('login').get()

  //  test input "name" (required/pattern)
  const name = form('login').get('name')

  // test inputs (required/pattern + validator)
  // - doesn't call the internal validator
  const loginValues = form('login').get((values, next) => {
    if (values.name.length > 10) return true
    return { name: 'wrong_length' }
   })
  // - call the internal validator
  const loginValues = form('login').get((values, next) => {
    if (values.name.length > 10) return [{ name: 'wrong_length' }, ...next(values)]
    return true
  })

  //  test input "name" (required/pattern + validator)
  const name = form('login').get('name', value => {
    if (value.length > 10) return true
    return 'wrong_length'
   })

@fabienjuif fabienjuif removed their assignment Jan 10, 2019
@fabienjuif fabienjuif added help wanted Extra attention is needed feature labels Jan 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants