react-forms icon indicating copy to clipboard operation
react-forms copied to clipboard

[V4] Update documentation

Open rvsia opened this issue 4 years ago • 10 comments

Scope: Docs

Description

Update documentation:

  • [ ] form state manager details
    • [ ] form props
    • [ ] form state
    • [ ] field props
    • [ ] field state
  • [x] new imports esm/cjs
    • [x] toggle in code examples
  • [x] required css loaders for
    • [x] ant
    • [x] PF4
  • [ ] remove links to react-final-form
  • [x] migration guide v2 > v3

rvsia avatar Jan 18 '21 09:01 rvsia

@rvsia Please also add documentation for api usage of manual validation. It would be great to use the schema to validate posted field values on server side without rendering.

zgover avatar Jun 09 '21 08:06 zgover

@zgover can you provide a simple example?

Hyperkid123 avatar Jun 09 '21 09:06 Hyperkid123

@Hyperkid123 Say form values were posted to an API /api/endpoint?schemaId=123&[email protected]&...

While processing the request to verify the parameters/values were valid using a defined schema

const schema = {
  fields: [
    { name: email, validate: [{type: 'required'}, {type: 'pattern', pattern: '^...$', message: 'Invalid email' }]
  }
}

function handler(req, res) {
  const { query: { schemaId, ...fieldValues } }  = req
  const invalidFields = validateFields(schema, fieldsValues)
  if (invalidFields.length > 0) {
    return res.status(400).json({ status: 'error', error: { field_errors: invalidFields, ... } })
  }
  res.status(200).json({ status: 'success', code: 200 })
}

zgover avatar Jun 09 '21 09:06 zgover

Ah, I see. There should be similar functionality on the submit event. This would basically fall into the global validation category but instead of evaluating it client-side function, we would wait for a Promise response.

Hyperkid123 avatar Jun 09 '21 09:06 Hyperkid123

@zgover So, you want to have a separate "validation engine" based on the DDF schema to use outside the form renderer, right? This sounds like an interesting idea! 🤔

rvsia avatar Jun 09 '21 09:06 rvsia

Maybe something available before v4? Should be easy to implement without breaking changes.

zgover avatar Jun 09 '21 09:06 zgover

@zgover Yeah, I will take a look on it today. And it would be a definitely just an addition, so we can release it asap.

rvsia avatar Jun 09 '21 09:06 rvsia

The validation engine is available even now. It's just not prepared to "consume" schema but only a field state.

Hyperkid123 avatar Jun 09 '21 10:06 Hyperkid123

@zgover Hello, the standalone validation has been released, you can check it here: https://data-driven-forms.org/utilities/standalone-validation

rvsia avatar Jun 10 '21 12:06 rvsia

Much appreciate the quickness @rvsia and @Hyperkid123

zgover avatar Jun 10 '21 15:06 zgover