Skip to content

onChange callback not triggered when field values are set via script #79

@maulikp9898

Description

@maulikp9898

Description

When programmatically setting field values using the script property in a form field definition, the onChange callback is not triggered on the LetsForm component, even though the form data is correctly updated.

Expected Behavior

When setFieldValue() is executed via script, the form's onChange callback should be triggered with the updated form data
The component should behave consistently whether values are changed by user interaction or programmatic updates

Actual Behavior

  • setFieldValue() updates the field value successfully
  • The onChange callback is not triggered when values are set via script
  • Form submission works correctly - onSubmit callback receives the updated values

Steps to Reproduce

  • Create a form with a field that has a script property using setFieldValue()
  • Set up an onChange callback on the LetsForm component
  • Load the form (script executes and sets the field value)
  • Observe that onChange is not called despite the field value being updated

Example Code

{
  "$schema": "https://cdn.jsdelivr.net/npm/lets-form/schemas/react-rsuite5/form.json",
  "version": 2,
  "layout": "vertical",
  "validationMode": "onSubmit",
  "labelSubmit": "Submit",
  "labelCancel": "Cancel",
  "fields": [
    {
      "component": "input-text",
      "name": "field_1",
      "label": "Field 1",
      "script": "setFieldValue('field_1', \"test\");",
      "react-rsuite5": {
        "fullWidth": true
      }
    }
  ]
}

Additional Context

  • Form submission works correctly and returns updated values in onSubmit
  • Only programmatic updates via script don't trigger onChange
  • User interactions (typing, clicking, etc.) properly trigger onChange as expected

Environment

LetsForm version: ^0.13.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions