-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mirek Simek
committed
Mar 7, 2019
0 parents
commit 66dd5d4
Showing
14 changed files
with
9,413 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", {}] | ||
] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[ignore] | ||
|
||
[include] | ||
|
||
[libs] | ||
|
||
[lints] | ||
|
||
[options] | ||
|
||
[strict] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = ''; | ||
} | ||
|
||
``` |
Oops, something went wrong.