Last active
June 16, 2020 21:25
-
-
Save chrismllr/1bc8b246868638d54f60db6a3c21ff82 to your computer and use it in GitHub Desktop.
ember-validation-state
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
import Controller from '@ember/controller'; | |
import { tracked } from '@glimmer/tracking'; | |
import { action } from '@ember/object'; | |
import validationState, { validate } from 'ember-validation-state'; | |
import { task } from 'ember-concurrency-decorators'; | |
import { timeout } from 'ember-concurrency'; | |
const validators = { | |
username: [validate('presence', { presence: true })], | |
password: [ | |
validate('length', { min: 8 }), | |
validate('presence', { presence: true }) | |
] | |
}; | |
export default class ApplicationController extends Controller { | |
@tracked username = ''; | |
@tracked password = ''; | |
@tracked fieldsEntered = 0; | |
@validationState(validators) form; | |
get enteredAllFields() { | |
return this.fieldsEntered >= 2; | |
} | |
@action update(field, event) { | |
this[field] = event.target.value; | |
} | |
@action exitField(field) { | |
this.fieldsEntered++; | |
} | |
@task | |
*submit(e) { | |
e.preventDefault(); | |
if (!this.form.isValid) { | |
return; | |
} | |
yield timeout(1000); | |
} | |
} |
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
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": false | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-data": "3.18.0", | |
"ember-validation-state": "0.0.2", | |
"ember-concurrency": "1.1.7", | |
"ember-concurrency-decorators": "1.0.0", | |
"ember-truth-helpers": "2.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment