TanStackT
TanStack6mo ago
19 replies
worthy-azure

Form level isDefaultValue always false.

I have code like this in my form:

<form.Subscribe
  selector={(state) => [state.canSubmit, state.isSubmitting, state.isDefaultValue]}
  children={([canSubmit, isDefaultValue]) => (
    <div>
      {JSON.stringify({ canSubmit, isDefaultValue })}
    </div>
  )}
/>


The isDefaultValue there is always false. I tried also doing reset inside useEffect, also with delay (setTimeout), with both keepDefaultValues true and false. Nothing changes.

I tried to investigate which of the fields is not default:

  render: function Render({ form, onUploadMedia, detail, subject, className }) {
    for (const [k, v] of Object.entries(form.fieldInfo)) {
      if (v.instance?.getMeta().isDefaultValue) {
        continue;
      }
      console.log('!DBG', k, v.instance?.getMeta().isDefaultValue);
    }

    setTimeout(() => {
      let allDefault = true;
      for (const [k, v] of Object.entries(form.fieldInfo)) {
        if (v.instance?.getMeta().isDefaultValue) {
          continue;
        }
        allDefault = false;
        console.log('!DBG 2000', k, v.instance?.getMeta().isDefaultValue);
      }
      console.log('!DBG ALL DEFAULT 2000', allDefault);
    }, 2000);


And according to this, all fields are at their default value.

Any idea what might be happening?

My version of @tanstack/react-form is 1.14.1
Was this page helpful?