Skip to content

Commit c5905be

Browse files
committed
Improve validation
1 parent b5110dd commit c5905be

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ import { ValidationResult, ValidatorMapFunc, ValidatorAction } from 'ember-chang
229229

230230
## Alternative Changeset
231231

232-
Enabled in 4.1.0
232+
Enabled in 4.1.0. Experimental and subject to changes until 5.0.
233233

234234
We now ship a ValidatedChangeset that is a proposed new API we would like to introduce and see if it jives with users. The goal of this new feature is to remove confusing APIs and externalize validations.
235235

236236
- ✂️ `save`
237237
- ✂️ `cast`
238238
- ✂️ `merge`
239239
- `errors` are required to be added to the Changeset manually after `validate`
240-
- `validate` takes a callback with the sum of changes. In user land you will call `changeset.validate((changes) => yupSchema.validate(changes))`
240+
- `validate` takes a callback with the sum of changes and original content to be applied to your externalized validation. In user land you will call `changeset.validate((changes) => yupSchema.validate(changes))`
241241

242242
```js
243243
import Component from '@glimmer/component';
@@ -274,7 +274,6 @@ export default class ValidatedForm extends Component {
274274
try {
275275
await this.changeset.validate((changes) => FormSchema.validate(changes));
276276
this.changeset.removeError(path);
277-
await this.model.save();
278277
} catch (e) {
279278
this.changeset.addError(e.path, { value: this.changeset.get(e.path), validation: e.message });
280279
}
@@ -285,6 +284,7 @@ export default class ValidatedForm extends Component {
285284
event.preventDefault();
286285

287286
changeset.execute();
287+
await this.model.save();
288288
}
289289
}
290290
```

0 commit comments

Comments
 (0)