jquense / yup

Dead simple Object schema validation
MIT License
22.94k stars 935 forks source link

Yup is not support multiple validation in one field #2125

Closed sumantaparida closed 1 year ago

sumantaparida commented 1 year ago

Describe the bug Yup is not test multiple validation, I want to validate in one field like

min , max, oneOf and regex validate with one field.

This is the code

      validations.forEach(Item => {
        if (Item.size) {
          fieldSchema = Yup.string().min(Item.size?.min, Item.message).max(Item.size?.max, Item.message);
        }
        if (Item.regexp) {
          fieldSchema = Yup.string().matches(Item.regexp.pattern, Item.message);
        }
        if (Item.in) {
          fieldSchema = Yup.string().oneOf(Item.in, Item.message || `List value ${Item.in}`);
        }
      });

Expected behavior A clear and concise description of what you expected to happen.

Platform (please complete the following information):

Additional context Add any other context about the problem here.

jquense commented 1 year ago

schema are immutable, your example is not setting multiple validations its only setting validations once because you aren't using fieldSchema in each if branch