最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vue.js - Vuelidate 2.0.3, issue with validate collection - Stack Overflow

programmeradmin1浏览0评论

I've got problem to handle simple array of string validation. I wanted to check if they're a valid yt or vimeo links.

My rules looks like that:

const mediaUrls = ref<string[]>([''])

const rules = computed(() => ({
    mediaUrls: {
        $each: helpers.forEach({ url: ytOrVimeoValidation })
    }
}))

And I'm using in template myInput component which provides some actions:

<template v-for="(_,index) in mediaUrls" :key="index">
    <MyInput
      v-model="mediaUrls[index]"
      :fieldLabel="index === 0 ? 'Add a Video Link' : ''"
      :isFailedValidation="$v.mediaUrls.$each[index]?.$error"
      :validationErrorMessage="$v.mediaUrls.$each[index]?.$errors?.[0]?.$message.toString()"
      @blur="handleVideoBlur(index)"
      @input="handlePortfolioVideo(index)"
    />
</template>
<button @click="add">Add new input</button>

What i'm trying to do in handleVideoBlur method is $touch() the proper index. But when I provided incorrect url.. I can't show proper message which I have in my ytOrVimeoValidation validator.

Inside $v.mediaUrls.$each.$response.$data I have Object with empty objects (there are as many objects as characters in the url) Inside $v.mediaUrls.$each.$response.$errors I have Array with object (if i have one input) and inside this object is empty arrays (the same situation as above with number of arrays)

Button just push empty string to mediaUrls array for render new input.

Anyone knows how to deal with that problem?

发布评论

评论列表(0)

  1. 暂无评论