Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@pgangwani

Description

@pgangwani

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

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