Skip to content

.setValue does not exists on controller or lens #12984

@freddi301

Description

@freddi301

Is your feature request related to a problem? Please describe.
.setValue does not exists on controller or lens, it is difficult to work wirh nested from components

Describe the solution you'd like
I'd like lens.setValue() or useController().setValue()

Describe alternatives you've considered
For now my cumbersome and untyped workaround is:

function MyNestedFormComponent({formLens}:{formLens: Lens<{name: string}>}){
  const nameController = useController(formLens.focus("name").interop());
  const nameOnChange = nameController.field.onChange;
  useEffect(() => {
    nameOnChange({target: {value: "John Doe"}})
  }, [nameOnChange])
}

I am not prop drilling const setMyField = (value) => form.setValue("myField", value) since it would defeat the purpose to have reausable form components operating with lenses

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestrequest a feature to be addedwaiting-up-voteWaiting for votes from the community.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions