Skip to content

Supply all props to validator as second argument #6787

@scottbedard

Description

@scottbedard

What problem does this feature solve?

Right now (2.4.4), props can be validated based on their value, but are unable to take other props into consideration. With access to a props object, we could do more complex validation.

For example, imagine a component with a foo and bar prop, where at least one of these props must be defined. Currently, this logic would have to be placed in the component's lifecycle hooks or render function. I would like the ability to keep it within the validator functions, as I think it's a more appropriate place for the logic.

What does the proposed API look like?

export default {
  props: {
    foo: {
      validator: (foo, props) => foo || props.bar
    },
    bar: {
      validator: (bar, props) => bar || props.foo
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions