8000 replace changeset workaround w/ correct helper usage · json-api-dotnet/TodoListExample@eb3fbb7 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb3fbb7

Browse files
replace changeset workaround w/ correct helper usage
1 parent 407bcd7 commit eb3fbb7

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

TodoListClient/app/components/forms/todo-item-form/component.js

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,22 @@
11
import Component from '@glimmer/component';
22
import { action } from '@ember/object';
33
import { inject as service } from '@ember/service';
4-
import Changeset from 'ember-changeset';
5-
import lookupValidator from 'ember-changeset-validations';
6-
import TodoItemValidations from '../../../validations/todo-item';
74

85
export default class TodoItemForm extends Component {
96
@service notify;
107
@service router;
118

12-
constructor() {
13-
super(...arguments);
14-
15-
// Was unable to use the changeset helpr, so I'm constructing the changeset manually.
16-
// Most likely related to this issue, but the fix didn't work.
17-
// https://github.com/poteto/ember-changeset-validations/issues/214
18-
this.changeset = new Changeset(
19-
this.args.todoItem,
20-
lookupValidator(TodoItemValidations),
21-
TodoItemValidations
22-
);
23-
}
24-
259
@action
2610
async save(event) {
2711
event.preventDefault();
2812
try {
29-
await this.changeset.validate();
13+
await this.args.changeset.validate();
3014

31-
if (this.changeset.isValid) {
32-
await this.changeset.save();
15+
if (this.args.changeset.isValid) {
16+
await this.args.changeset.save();
3317
this.router.transitionTo('s.todo-items');
3418
} else {
35-
const errors = this.changeset.errors
19+
const errors = this.args.changeset.errors
3620
.map((error) => `${error.validation} <br />`)
3721
.reduce((accumulator, currentValue) => accumulator + currentValue);
3822
this.notify.error({ html: errors });
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Controller from '@ember/controller';
2+
import TodoItemValidations from '../../../validations/todo-item';
3+
4+
export default class AddController extends Controller {
5+
TodoItemValidations = TodoItemValidations;
6+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<Forms::TodoItemForm @todoItem={{this.model}} />
1+
<Forms::TodoItemForm @changeset={{changeset this.model this.TodoItemValidations}} @todoItem={{this.model}} />

0 commit comments

Comments
 (0)
0