Skip to content
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

Custom 'required' error message doesn't work on fields with 'refValueFor' prop. #168

Open
thomasters17 opened this issue Mar 25, 2024 · 1 comment

Comments

@thomasters17
Copy link

When a required field also has a refValueFor prop, it no longer returns a custom required error message and instead, falls back to the default NAME is a required field message.

To see the issue, copy the following test into confrim-password.test.js

describe("Custom required error message", () => {
  let loginSchema, config, schema;

  beforeEach(() => {
    loginSchema = {
      $schema: "http://json-schema.org/draft-07/schema#",
      $id: "http://example.com/login.schema.json",
      title: "Login",
      description: "Login form",
      type: "object",
      ...innerSchema,
    };

    config = {
      logging: true,
      // for error messages...
      errMessages: {
        password: {
          "required": "Enter a new password",
          "pattern": "Please enter a valid password"
        },
        confirmPassword: {
          "required": "Enter a confirm password",
          "refValueFor": "Confirm password field must have the same value as New password"
        }
      }
    };
    schema = buildYup(loginSchema, config);
  });

  it("should show custom error message for required field", async () => {
    try {
      schema.validateSync({
        username: "jimmy",
        password: "xyz123"
      });
    } catch (e) {
      expect(e.errors[0]).toBe("Enter a confirm password");
    }
  });

  it("should show custom error message for refsFor field", async () => {
    try {
      schema.validateSync({
        username: "jimmy",
        password: "xyz123",
        confirmPassword: "xyz1234",
      });
    } catch (e) {
      expect(e.errors[0]).toBe("Confirm password field must have the same value as New password");
    }
  });
})
@thomasters17
Copy link
Author

I have tried to debug the issue locally using the test provided above but don't understand the code well enough to get to the bottom of it. This functionality was working up until release V1.12.14. in V1.12.15 the Yup dependency was updated to V1.0.0 which broke this functionality. I know that you are not really maintaining this library much anymore but if you could help me look into it that would be very much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant