-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
3 changed files
with
46 additions
and
17 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
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 |
---|---|---|
@@ -1,38 +1,67 @@ | ||
ember-validation-decorator | ||
============================================================================== | ||
# `ember-validation-state` | ||
|
||
[Short description of the addon.] | ||
Provides an Octane-ready decorator which can be used in conjunction with ember-validation validators, to provide form field validation state. | ||
|
||
This addon takes heavy inspiration, and is based mostly upon, the work in [`ember-cp-validations`](https://github.com/offirgolan/ember-cp-validations), but with a more straightforward approach, and smaller API. | ||
|
||
Compatibility | ||
------------------------------------------------------------------------------ | ||
|
||
## Compatibility | ||
|
||
* Ember.js v3.12 or above | ||
* Ember CLI v2.13 or above | ||
* Node.js v10 or above | ||
|
||
|
||
Installation | ||
------------------------------------------------------------------------------ | ||
## Installation | ||
|
||
``` | ||
ember install ember-validation-decorator | ||
ember install ember-validation-state | ||
``` | ||
|
||
|
||
Usage | ||
------------------------------------------------------------------------------ | ||
## Usage | ||
|
||
```js | ||
import validationState, { validate } from 'ember-validation-state'; | ||
|
||
const Validators = { | ||
username: [validate('presence', { presence: true })], | ||
password: [validate('length', { min: 6 })] | ||
}; | ||
|
||
class MyForm extends Component { | ||
@tracked username = null; | ||
@tracked password = null; | ||
|
||
@validationState(Validators) validationState; | ||
} | ||
``` | ||
|
||
[Longer description of how to use the addon in apps.] | ||
### ValidationState type definition | ||
|
||
```ts | ||
interface AttributeValidation { | ||
messages: string[]; | ||
isValid: boolean; | ||
} | ||
|
||
interface Attrs { | ||
[propertyName: string]: AttributeValidation; | ||
} | ||
|
||
interface ValidationState { | ||
isValid: boolean; | ||
attrs: Attrs | ||
} | ||
``` | ||
|
||
## Contributing | ||
|
||
Contributing | ||
------------------------------------------------------------------------------ | ||
|
||
See the [Contributing](CONTRIBUTING.md) guide for details. | ||
|
||
|
||
License | ||
------------------------------------------------------------------------------ | ||
## License | ||
|
||
|
||
This project is licensed under the [MIT License](LICENSE.md). |
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