npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quasar-app-extension-vuelidate-rules

v0.5.1

Published

Use Vuelidate methods as internal Quasar rules for validation

Downloads

1,594

Readme

Quasar App Extension Vuelidate Rules

The elegance of Quasar's internal validation with the power of Vuelidate's built-in validators.

Quasar Framework offers a very practical way to validate form fields, using the rules attribute in Field wrapper, input and select component. The attribute accepts an array of functions that returns true or a string with an error message.

In most cases this is enough, but in some cases you need more complex validations. Quasar's documentation recommends Vuelidate as an external validation solution, but using this approach has a downside: You cannot use external validation to validate child components of a Form.

Leveraging the power of Vuelidate also requires more code to set up a validation, add the validations property to the component to define the rules and bind the error and error-message attributes of the component.

This extension exposes Vuelidate methods so they can be used as Quasar internal rules.

More information about Quasar Validation: https://quasar.dev/vue-components/field#Validation and Form component: https://quasar.dev/vue-components/form

Install

Quasar 2 compatible ( => version 0.4.0 )

quasar ext add vuelidate-rules

For Quasar 1, please use version 0.3.2

Usage

The extension will inject the $rules object to the Vue instance, the rules will then be available in the components. The customized error message is optional, always as the last parameter, and if not provided it will return false.

  • If no parameters are needed:
    $rules.alpha() 
    $rules.alpha('Please use only letters')
  • If parameters are needed:
    $rules.between(10,100)
    $rules.between(10,100, 'Please enter a number between 0 and 100')

Available methods

| rule | parameters| description | |--------------|------------ | --- | | required | none | Requires non-empty data. Checks for empty arrays and strings containing only whitespaces. | requiredIf | ref | Requires non-empty data only if the reference evaluates to true. | requiredUnless | ref | Requires non-empty data only if the reference evaluates to false. | minLength | length integer | Requires the input to have a minimum specified length, inclusive. Works with arrays. | maxLength | length integer | Requires the input to have a maximum specified length, inclusive. Works with arrays. | minValue | value integer | Requires entry to have a specified minimum numeric value or Date. | maxValue | value integer | Requires entry to have a specified maximum numeric value or Date. | between | min integer, max integer | Checks if a number or Date is in specified bounds. Min and max are both inclusive. | alpha | none | Accepts only alphabet characters. | alphaNum | none | Accepts only alphanumerics. | numeric | none | Accepts only numerics. | integer | none | Accepts positive and negative integers. | decimal | none | Accepts positive and negative decimal numbers. | email | none | Accepts valid email addresses. Keep in mind you still have to carefully verify it on your server, as it is impossible to tell if the address is real without sending verification email. | ipAddress | none | Accepts valid IPv4 addresses in dotted decimal notation like 127.0.0.1. | macAddress | separator string, (default ':') | Accepts valid MAC addresses like 00:ff:11:22:33:44:55 | url | none | Accepts only URLs. | isTrue | none | Only accepts a true value | or | other rules | Passes when at least one of provided rules passes | and | other rules | Passes when all of provided validators passes. | not | rule | Passes when provided validator would not pass | is | value | Passes when the field value is the same as the provided value, for example true | sameAs | value | Passes when field value is the same as other field value

  • All methods receive a last optional parameter with the customized error message.

Examples

Using several rules

<q-input
    v-model="form.name"
    label="Your name *"
    hint="Name and surname"
    :rules="[
      $rules.required('Your name is required'),
      $rules.alpha('Your name should not have numbers'),
      $rules.minLength(3, 'Your name should have at least 3 letters'),
      $rules.maxLength(10, 'Your name should not be larger than 10 letters') 
    ]"
/>

Using logic operators

<q-input
    v-model="form.age"
    label="Your age *"
    :rules="[
      $rules.or($rules.between(10,15), $rules.between(20,25)),
    ]"
/>
<q-input
    v-model="form.age"
    label="Your age *"
    :rules="[
      $rules.or(
        $rules.and(
          $rules.between(10,17),
          $rules.between(16,25)
        ),
        $rules.minValue(17),
        'Or nd message 2'
      ),
    ]"
  />

Modified methods

These methods are not the original Vuelidate methods but modified versions

TBD

Other not Vuelidate methods

Check if is a specific value. This is not a method of Vuelidate but may be useful, so it was added. Can be tied to other data properties, for example to check if a password is the same as the confirmation (not reactive yet)

<q-field
        :value="form.accept"
        label="Please read the license"
        stack-label
        :rules="[
           $rules.is(true, 'Please accept the license')
        ]"
      >
        <q-toggle v-model="form.accept" label="I accept the license and terms" />
</q-field>

To do

  • Make locator based methods like sameAs or requiredIf to work, or develop an alternative

Related projects

  • Quasar Framework https://quasar.dev/
  • Vuelidate https://vuelidate.js.org
  • NeQu (Nest + Quasar Boilerplate) https://github.com/cuatromedios/nequ