-
-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(form-core): isDirty flag #598
Conversation
23c03a2
to
3e4f6b4
Compare
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 5514714. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only updated this file to make the PR more easy to test, we don't have to keep these changes!
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #598 +/- ##
==========================================
- Coverage 87.78% 87.54% -0.25%
==========================================
Files 31 31
Lines 819 851 +32
Branches 184 200 +16
==========================================
+ Hits 719 745 +26
- Misses 95 100 +5
- Partials 5 6 +1 ☔ View full report in Codecov by Sentry. |
const fieldDefaultValue = getBy( | ||
this.form.options.defaultValues, | ||
this.name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it OK to assume that passing this.form.options.defaultValues
as the first argument to getBy()
will never result in an error? defaultValues
cannot be null
, or any other value that could cause us trouble here, right? 😅
@@ -696,3 +705,46 @@ function getErrorMapKey(cause: ValidationCause) { | |||
return 'onChange' | |||
} | |||
} | |||
|
|||
export function deepEqual<T>(objA: T, objB: T): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is a modified version of shallow
from tanstack/store
: https://github.com/TanStack/store/blob/be32993f5224c8e60ce6c3fe6674ec5907713f80/packages/react-store/src/index.ts#L27-L55
cbbcad3
to
69ffa6e
Compare
69ffa6e
to
4d88b28
Compare
selector={(state) => [ | ||
state.canSubmit, | ||
state.isSubmitting, | ||
state.isDirty, | ||
]} | ||
children={([canSubmit, isSubmitting, isDirty]) => ( | ||
<> | ||
<button type="submit" disabled={!canSubmit}> | ||
{isSubmitting ? '...' : 'Submit'} | ||
</button> | ||
<p> | ||
<code>isDirty:{isDirty ? 'true' : 'false'}</code> | ||
</p> | ||
</> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's revert this from the example :)
Hey @fulopkovacs sorry for not clarifying this much sooner - as I was busy wrapping up my book. Now that I've done so, let my sample some writing from a (currently unpublished) blog post I wrote about forms validation states:
As we can see here, The way I did this in HouseForm was by:
I think we should set up our structure to be very similar and even provide What do you think? |
I'm personally happy to rely on your experience with form libraries, and use these four form validation states. My only concern is that some users coming from React Hook Form were asking for an Here's an example that one user gave when I asked them how would they use the
And here's a use case for this flag from another user:
If I understand it correctly, the four states you describe ("Touched", "Pristine", "Dirty", "Disabled") cannot be used to achieve what they want. My question is: what should be the recommended way for these users to get the results they want? Should we add a new flag (that is not called I personally would find a flag that does the same thing as the What do you think? |
The Consider the following:
Should they be prevented because they did, technically, interact with the form. I'd say "yes" and vote that to be our default functionality. Instead of changing that, let's provide the We can even make a documentation note for this if users are coming from RHF |
Nice! I think this is the best solution. It allows us to follow Cruthchley's Four Input States Model™️ , while providing an API for our users to get the data they were asking for. I'll update the PR! |
4d88b28
to
5514714
Compare
Closing as I know @fulopkovacs has a more up-to-date PR coming soon 🎉🎉 |
Adding the
isDirty
flag to the form and fields inspired byreact-hook-form
.Description
true
?field.state.meta.isDirty
form.state.isDirty
TODO
Motivation
This feature was request on Discord multiple times: