Giter Site home page Giter Site logo

Comments (5)

TheJaredWilcurt avatar TheJaredWilcurt commented on July 27, 2024

Been using Vee-Validate 2 at work for about 2.5 years. Version 3 is a completely different library/approach. So rather than update to it and re-write our codebase with it in mind, we are considering evaluating other options (like Vuelidate), or simply not using a validation library. More than 60% of the time we handle the validation of elements on a page by hand anyways.

Often because the validation we have is not based on the input, but the context of the input with other inputs. Like not allowing the user to set the "start date" after the "end date" on a reservation. Stuff like this is just too easy to do in Vue via a computed property, and too complicated to bother with having a 3rd-party library handle it.

I'm against the addition of any automated validation. Especially with this API, as there are just way too many edge cases you would need to validate for (email, phone (dear god), credit card, min/max length, ASYNC UNIQUE NAME VALIDATION OMG, alpha only, regex, etc). Vee-Validate actually lists 27 different types. That would be quite the large object, and a lot of bloat for Vuetensils, which is meant to be a a small, style-free, A11Y focused component library.

If users want validation, there are several existing options they could pull in. Perhaps, just showing an example page in the docs of how to pair Vuetensils with Vuelidate and Vee-Validate would be better.

With that said, though I'm against having the validation logic in Vuetensils, showing a validation message under an input is very common. I wouldn't mind a single prop for passing in a validationErrorMessage="string". So that my parent component or 3rd-party validation plugin can handle the validation, and then just pass in some text to be displayed if there is a problem. A custom class prop for this would be nice to control the styling of it based on success/failure messages.

from vuetensils.

AustinGil avatar AustinGil commented on July 27, 2024

Yeah, I get your point, but there is already some validation logic baked in, using just HTML validators and the Validity API. The amount of code needed to support basic error messages is not so much:

errorMessages() {
      const { errors, invalid, $attrs } = this;
      if (!errors || !isType(errors, 'object')) return false;

      const messages = {};

      for (const attr of [
        'type',
        'required',
        'minlength',
        'maxlength',
        'min',
        'max',
        'pattern',
      ]) {
        if (invalid[attr] && errors[attr]) {
          messages[attr] = isType(errors[attr], 'function')
            ? errors[attr]($attrs[attr])
            : errors[attr];
        }
      }

      return Object.keys(messages).length ? messages : undefined;
    },```

Could possibly be even less. But it would be much less than adding something like Vuelidate (which BTW, I would recommend if you're looking for some more powerful validation lib). 

from vuetensils.

AustinGil avatar AustinGil commented on July 27, 2024

@TheJaredWilcurt

Another option is to include something like what Vuetify does with its rules prop https://vuetifyjs.com/en/components/inputs/#rules

I like it because the validation logic is passed off to the user to implement. Then we could provide validators that could be imported optionally, but are not included by default. So it could be something like

<template>
  <VInput :rules="rules" />
</template>

<script>
import {required, minLength, maxLength} from 'vuetensils/validators' // or any other validator
export default {
  data: () => ({
    rules: [
      required('this value is required'),
      minLength(2, 'Must be greater than 2'),
      maxLength(10, 'Cannot exceed 10')
    ]
  })
}
</script>

This is just a theoretical design

from vuetensils.

TheJaredWilcurt avatar TheJaredWilcurt commented on July 27, 2024

Yeah, I think that's better

from vuetensils.

AustinGil avatar AustinGil commented on July 27, 2024

Finally got around to publishing what I think it s good solution https://vuetensils.austingil.com/components/input.html#validation

from vuetensils.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.