Skip to content

isDirty from useField is true, when you change initialValue, but new initial value is not set. #7925

Open
@kspacja

Description

@kspacja

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

8.0.1

What package has an issue?

@mantine/form

What framework do you use?

Vite

In which browsers you can reproduce the issue?

Not applicable – issue is not related to the browser

Describe the bug

const initialType = useMemo(
    () => getInitialType(value, chips),
    [value, chips]
  );

  const activeField = useField<DurationInputType>({
    initialValue: initialType,
  });

  console.log({isDirty: activeField.isDirty(), activeValue});

Maybe this is not a bug, but a feature, but on the first sight it looks not right. My initialValue has changed in time, what causes isDirty returned value to true, what is unintuitive because value is not changed programmatically (by setValue) or by user in an input.

This is fragment from @mantine/forms code, which is responsible for that:

// @mantine/form/esm/use-field.mjs
const isDirty = useCallback(() => valueRef.current !== initialValue, [initialValue]);

If this is a feature, not a bug, I would like to ask you to help, how I should be done.

If possible, include a link to a codesandbox with a minimal reproduction

No response

Possible fix

No response

Self-service

  • I would be willing to implement a fix for this issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions