A
A
AndreySergienko2022-03-29 15:50:26
JavaScript
AndreySergienko, 2022-03-29 15:50:26

How to validate and generate a rules object for a heavily nested vuelidate form?

const formData = reactive({
      name: {
        value: '',
        validate: {
          required: true,
          min: 2
        }
      },
      phone: {
        value: '',
        validate: {
          min: 2,
          required: true,
        }
      },
      // Позицию добавляются динамически, изначально их нет. Должна быть хотя бы одна.
      positions: [
        // Пример объекта позиций
        {
          inn: {
            value: '',
            validate: {
              required: true,
              min: 11
            }
          },
          // Позиция в свою очередь может иметь ещё доп параметры. Не обязательно они должны быть
          addParameters: [
            {
              name: 'Сопроводительная документация',
              // В случае input объект выглядит так
              type: 'input',
              balls: {
                value: '',
                validate: {
                  required: true
                }
              },
              vk: {
                value: '',
                validate: {
                  required: true
                }
              }
            },
            {
              name: 'Сертификат',
              type: 'select',
              parameters: [
                {
                  name: {
                    value: '',
                    validate: {
                      required: true
                    }
                  },
                  balls: {
                    value: '',
                    validate: {
                      required: true
                    }
                  },
                  vk: {
                    value: '',
                    validate: {
                      required: true
                    }
                  }
                }
              ]
            }
          ]
        }
      ]
    })


The question is how to form the rules object from the formData object. By taking away the validate fields, they should turn into full-fledged rules in rules.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question