Skip to content

Commit

Permalink
initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirek Simek committed Mar 7, 2019
0 parents commit 66dd5d4
Show file tree
Hide file tree
Showing 14 changed files with 9,413 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["@babel/preset-flow"],
"plugins": [
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", {}]
]
}

60 changes: 60 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module.exports = {
root: true,

parserOptions: {
parser: 'babel-eslint',
sourceType: 'module'
},

env: {
browser: true,
"cypress/globals": true
},

// https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
// consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
extends: [
'plugin:vue/essential',
'airbnb-base'
],

// required to lint *.vue files
plugins: [
'vue',
'cypress'
],

globals: {
'ga': true, // Google Analytics
'cordova': true,
'__statics': true,
"cy": false,
"Cypress": false
},

// add your custom rules here
rules: {
'no-param-reassign': 'off',
'prefer-promise-reject-errors': 'off',

'import/first': 'off',
'import/named': 'error',
'import/namespace': 'error',
'import/default': 'error',
'import/export': 'error',
'import/extensions': 'off',
'import/no-unresolved': 'off',
'import/no-extraneous-dependencies': 'off',

// allow console.log during development only
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
// allow debugger during development only
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',

indent: ['error', 4],
'max-len': ['warn', 140],
'no-underscore-dangle': ['off'],
'class-methods-use-this': ['off'],
'padded-blocks': ['off'],
}
};
11 changes: 11 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[ignore]

[include]

[libs]

[lints]

[options]

[strict]
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# OS Files
.DS_Store
Thumbs.db

# Dependencies
node_modules/

# Dev/Build Artifacts
/dist/
/tests/e2e/demo/public/browser/dist/
/tests/e2e/videos/
/tests/e2e/screenshots/
/tests/e2e/fixtures/public/packages/
/tests/unit/coverage/
jsconfig.json

# Local Env Files
.env.local
.env.*.local

# Log Files
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Unconfigured Editors
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*
11 changes: 11 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store
node_modules
src
package-lock.json
publish.sh
yarn-error.log
yarn.lock
.idea
.babelrc
.eslintrc.js
.flowconfig
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 Miroslav Simek ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
121 changes: 121 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# vuelidate property decorators

This library provides a thin wrapper of
[vuelidate](https://vuelidate.netlify.com/)
library to simplify its usage with `vue-class-component`
or `vue-property-decorator`.

## Installation

```bash
yarn add vuelidate-property-decorators
```

## Usage

Set up `vuelidate` library as described in (https://vuelidate.netlify.com/#sub-installation).

Then on your component:

### Validating single field

To set per-field validation, use the `@Validate` decorator:

```javascript

import {Validate} from 'vuelidate-property-decorators';
import {required} from 'vuelidate/lib/validators'

@Component({})
export default class AddressForm extends Vue {

@Validate({required})
firstName = '';

@Validate({required})
lastName = '';

}

```

Template (pug in this case) looks the same way as in pure `vuelidate`:

```pug
.form-group
q-input(v-model="$v.firstName.$model")
.error(v-if="!$v.firstName.required") Field is required
.form-group
q-input(v-model="$v.lastName.$model")
.error(v-if="!$v.lastName.required") Field is required
```

### Setting validation for all fields at once

To set the validation for all fields at once, use `@Validations` decorator:


```javascript

import {Validations} from 'vuelidate-property-decorators';
import {required} from 'vuelidate/lib/validators'

@Component({})
export default class AddressForm extends Vue {

firstName = '';
lastName = '';

@Validations()
validations = {
firstName: {required},
lastName: {required}
}

}

```

## Dynamic validations

Both the argument of `@Validate(...)` and the value of `@Validations()`
can be a function. In this case the function is called (reactively)
with `this` set to the component instance.

Example:

```javascript

import {Validate, Validations} from 'vuelidate-property-decorators';
import {required} from 'vuelidate/lib/validators'

@Component({})
export default class AddressForm extends Vue {

firstName = '';
lastName = '';

isRequired = false;

@Validations()
validations() {
if (this.isRequired) {
return {
firstName: {required},
lastName: {required}
}
}
return {}
}

@Validate(() => {
if (this.isRequired) {
return {required}
}
return {}
})
test = '';
}

```
Loading

0 comments on commit 66dd5d4

Please sign in to comment.