edmundhung / conform

A type-safe form validation library utilizing web fundamentals to progressively enhance HTML Forms with full support for server frameworks like Remix and Next.js.
https://conform.guide
MIT License
1.8k stars 101 forks source link

Potential Bug with shouldDirtyConsider and a Disabled Field #703

Closed ericsakmar closed 1 month ago

ericsakmar commented 2 months ago

Describe the bug and the expected behavior

Hello! It seems that shouldDirtyConsider is not being correctly applied when a field has been disabled.

I've pasted a Stackblitz below to show the problem. form.dirty is immediately true even though nothing else has changed and the shouldDirtyConsider is set to return true for any field other than email.

Thanks for reading!

Conform version

v1.1.5

Steps to Reproduce the Bug or Issue

Stackblitz

What browsers are you seeing the problem on?

No response

Screenshots or Videos

No response

Additional context

No response

edmundhung commented 1 month ago

Thanks for the PR, @ericsakmar! I am happy with the changes you made. But I would like to learn more about your usecase first before I have it merged.

The issue you had with shouldDirtyConsider was caused by the missing entry when the input is disabled. Although your PR does fix the dirty state, the validation is still failing due to missing value from the form data. I wonder if you are looking for a way to stop user from editing the input value, maybe you can use the readonly attribute instead?

ericsakmar commented 1 month ago

Yes, the readonly attribute does solve the problem I thought I had. Thanks!