-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
76200b7
commit 9898b5e
Showing
8 changed files
with
148 additions
and
15 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<form class="flex flex-col mb-8" {{on "submit" this.submit}}> | ||
<label for="" class="mb-4 flex flex-col"> | ||
<span class="text-sm font-bold mb-2">First Name</span> | ||
<input | ||
type="text" | ||
name="" | ||
value="" | ||
class="text-sm p-2 border mb-2" | ||
value={{this.firstName}} | ||
{{on "input" (pick "target.value" (fn (mut this.firstName)))}} | ||
{{on "input" (fn this.validator.validate "firstName")}} | ||
{{on "blur" (fn this.validator.validate "firstName")}} | ||
> | ||
{{#each this.validator.errors.firstName as |error|}} | ||
<span class="text-sm text-red-700 mb-1"> | ||
{{error}} | ||
</span> | ||
{{/each}} | ||
</label> | ||
|
||
<label for="" class="mb-4 flex flex-col"> | ||
<span class="text-sm font-bold mb-2">Last Name</span> | ||
<input | ||
type="text" | ||
name="" | ||
value="" | ||
class="text-sm p-2 border mb-2" | ||
value={{this.lastName}} | ||
{{on "input" (pick "target.value" (fn (mut this.lastName)))}} | ||
{{on "input" (fn this.validator.validate "lastName")}} | ||
{{on "blur" (fn this.validator.validate "lastName")}} | ||
> | ||
{{#each this.validator.errors.lastName as |error|}} | ||
<span class="text-sm text-red-700 mb-1"> | ||
{{error}} | ||
</span> | ||
{{/each}} | ||
</label> | ||
|
||
<div class="flex flex-row"> | ||
<button type="submit" class="bg-green-400 p-2 px-8 text-white" name="button">Validate</button> | ||
</div> | ||
</form> |
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,50 @@ | ||
import Component from '@glimmer/component'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { action } from '@ember/object'; | ||
import { Validator, test, only } from 'ember-vest'; | ||
import { task, timeout } from 'ember-concurrency'; | ||
|
||
@Validator('AsyncExample', function (data, changedField) { | ||
only(changedField); | ||
|
||
test('firstName', () => { | ||
return data.validateFirstName.perform(data.firstName); | ||
}); | ||
|
||
test('lastName', () => { | ||
return data.validateLastName.perform(data.lastName); | ||
}); | ||
}) | ||
export default class AsyncExampleComponent extends Component { | ||
@tracked firstName; | ||
@tracked lastName; | ||
|
||
@task({ restartable: true }) | ||
*validateFirstName(value = '') { | ||
yield timeout(300); | ||
|
||
if (value.length < 2) { | ||
return Promise.reject('First Name should be longer or equals 2'); | ||
} | ||
return Promise.resolve(); | ||
} | ||
|
||
@task({ restartable: true }) | ||
*validateLastName(value = '') { | ||
yield timeout(300); | ||
|
||
if (value.length < 2) { | ||
return Promise.reject('Last Name should be longer or equals 2'); | ||
} | ||
return Promise.resolve(); | ||
} | ||
|
||
@action async submit(e) { | ||
e.preventDefault(); | ||
await this.validator.validate(); | ||
|
||
if (this.validator.isValid) { | ||
alert('success'); | ||
} | ||
} | ||
} |
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
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