-
Notifications
You must be signed in to change notification settings - Fork 1
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
input starts dirty when hydrated #26
Comments
Thanks for the report, i'll get back to you once I have time to check the reasoning |
You bet! The reason I bring it up is because the current system works great when you start in an empty form, but if you want to start on a form with values already filled out, all the inputs with values with pre-filled data will be dirty, even though you never touched them yourself. One idea would be to create a new function signatrue allow users to pass in a secondary value that can be used as the value to compare against, instead of just relying on the initial value. Something like this existing
proposal
|
Before you spend any time on this, I have a POC solution working great locally, I need to head out for the day, but can open a starter PR to get the conversation going! |
If this idea goes ahead, personally I would propose a slightly different api signature:
This new option could help with this idea of passing an atom as the value. |
This should be doable once the react utils exports are done, can be followed here |
Sorry missed this, in both API's it seems like you already have access to the value you wish to compare against, why not just pass it to the atom to begin with? export const nameAtom = atomWithValidate("originalValue", {
validate: (name) => { ... },
});
For async atom creation, we don't have anything in this library right now which is why the original request makes sense, though the original jotai library doesn't signal a hydration on the atom which makes it hard for this to work with the original for SSR. @dai-shi how bad of an idea is it if we export the hydrated store for the library to make use of? |
Sorry, I don't follow. Can you elaborate please? Is it about jotai-form, or jotai itself? |
Jotai has a map of hydrated atoms that it uses to avoid double hydration on the same atom during SSR, would it be a problem if we exported a getter for that map? |
I see. As you may guess, I would like to avoid exposing it. |
The discussion is about being able to re-initialize the form atom with a different value over a period of time (which I think is a valid requirement) but, the API's presented by the other developers seem to point in a direction where the value is already known at initialization which doesn't make sense since you could just pass it as the initial value instead |
If |
in this case the setAtom would create a Dirty form so yep, we need a different helper. |
We could do something like so to allow the RESET, and also add in a wrapper to avoid the awkwardness of using the constants |
If I have an atom defined like this
and hydrate it via
the input will start as dirty, since "hello world" !== "". If an atom is hydrated, what it is hydrated with should be the initial value that is checked against to determine if the input is dirty or not.
The text was updated successfully, but these errors were encountered: