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

Issue: Validate is not working when schema is given in ZodField (listField, textField) #125

Open
pgangwani opened this issue May 13, 2024 · 0 comments

Comments

@pgangwani
Copy link

pgangwani commented May 13, 2024

Describe the bug
I am trying to add validate for some dependent validation in textField/string which is under listField and even outside, I noticed that validate function in not working. I saw same issue in your storybook too.

To Reproduce
Steps to reproduce the behavior:
Existing issue in storybook example:

  1. Go to 'storybook'
  2. Click on 'try to submit password & confirmPassword without match'
  3. Notice the error is not displayed
  4. Put console.log in validate in local, validate doesnt trigger
    Screenshot 2024-05-13 at 5 25 55 PM

Issue in my schema(test):

  1. I am using below create function to create my formAtom object and binding to respective tsx
// fieldsAtom creator
// This function is used to have isolated scope
export const fieldsCreatorTierConditions = () => {
  const unit = stringField({
    value: Unit.QUANTITY,
    preprocess(value) {
      return value;
    },
    name: 'unit',
    validate: ({ get, event, value }) => {
      debugger;
      console.info('UNIT:Validation: THIS IS NOT TRIGGERING');
    },
  });

  const values = listField({
    validate: ({ get, event, value }) => {
      debugger;
      console.info('ListField:VALIDATION,  this is not triggering where as listAtom works but not on Onchange of any fields in listAtom');
      console.info('list Validate:', value);
      return ['what an error', 'yeah its fine'];
    },
    value: [
      { min: '', max: '' },
      { min: '', max: '' },
      { min: '', max: '' },
    ],
    fields: ({ min = '', max = '' }) => ({
      min: stringField({
        name: 'min',
        value: min,
        schema: z.string().min(1),
        validate: ({ get, event, value }) => {
          debugger;
          console.log('min:validation: this is also not working,/triggering');
        },
      }),
      max: stringField({
        name: 'max',
        validate: ({ get, event, value }) => {
          debugger;
          console.log('max:validation: this is also not working,/triggering');
        },
        value: max,
      }),
    }),
  });
  return { unit, values };
};

to achieve this
image

  1. validate never fires with and without schema.
    3

Expected behavior
In both the above examples, I would like to see validate does its work. If schema cannot exist when validate exist then it should be clearly mentioned. Even without schema, validate should first work. Please provide some example or provide help.

Screenshots
Existing Issue:
Screenshot 2024-05-13 at 5 25 55 PM

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
I think we need to have enough complex examples to test / view in storybook

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