noble-ai / rescript-fields

Elaborate form validation for Rescript
https://noble-ai.github.io/rescript-fields
MIT License
1 stars 1 forks source link

Instantiating a `FieldArray` with a default `Field.input` breaks the form when adding new elements to `FieldArray` and making subseqeunt `filed.actions.set()` calls on those field elements. #4

Open KateChanthakaew opened 2 months ago

KateChanthakaew commented 2 months ago

Bug

When instantiating a Form FieldArray with ~init=some([Field.input]), the first FieldArray element can be updated as expected however subsequent elements added to the FieldArray do not honor their field.actions.set() updates. Store values are not set on the form as expected.

Reproduction

module LoginArray = {
  module Field = FieldArray.Make(
    Login.Field,
    {
      type t = Login.Field.t
      let filter = FieldArray.filterIdentity
    },
  )

  let validate = (out: Field.output) => {
    if out->Array.length < 2 {
      Error("Must choose at least two logins")
    } else {
      Ok()
    }
    ->Promise.return
    ->Promise.delay(~ms=1000)
  }

  let contextDefault: Field.context = {
    validate,
    empty: _ => [{username: "", password: ""}],
    element: Login.contextValidate,
  }

The VDO below shows that the second form element of the FieldArray not been updated as expected.

https://github.com/user-attachments/assets/9574bf72-c251-4f03-be26-e6eaf97a979e

Gotchas

https://github.com/user-attachments/assets/a80f3fd9-a512-4330-ac8f-af6a1268de8c

Expected Behavior