jquense / react-formal

Sophisticated HTML form management for React
http://jquense.github.io/react-formal
MIT License
526 stars 52 forks source link

`required` determination from yup schema inside a Field component #99

Closed rosskevin closed 8 years ago

rosskevin commented 8 years ago

I am providing material-ui components for react-formal to render. As part of the material design spec for required fields, I need to display an asterisk in the label.

With me so far? Great.

I'm using yup - awesome - love it. So:

Given a schema

const schema = yup.object({
  firstName: yup.string().trim().default('').required('First name is required')
})

When I render a custom material-ui field Then I need to inspect the yup schema to determine if it is required

I see that I receive meta with the StringSchema: form_-_dummy_com

I didn't spot anything in the yup api, can I query the StringSchema somehow to determine required?

jquense commented 8 years ago

try: https://github.com/jquense/yup#mixeddescribe-schemadescription,

it should give you a list of the schema tests (among other things)

rosskevin commented 8 years ago

Thanks Jason!

form_-_dummy_com