adopted-ember-addons / adopted-ember-addons/ember-changeset

Allow to call execute() even if isValid = false

Aperta
#559 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
425
Fork
136
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Use case that I am currently working on:

Checkbox to agree with Terms of Use. I add validator on that checkbox, that it should be "checked". If it is not checked - I show an error, that "they, you have to agree with it". So if I have such validator, calling `execute()` method, won't do anything, as `isValid` will be `false`. In cases like that, It should be allowed to update changeset even if the value will result in error.

My values for form fields comes from the `changeset` object. In cases like `input type="text"`, input gets updates in DOM and then it propagates to changeset. With checkbox, it is a bit different, as it is more DDAU than text one.

Here is a code in question:

```
execute() {
let oldContent;
if (this.isValid && this.isDirty) {
let content = this[CONTENT];
let changes = this[CHANGES];

// keep old values in case of error and we want to rollback
oldContent = buildOldValues(content, this.changes, this.getDeep);

// we want mutation on original object
// @tracked
this[CONTENT] = mergeDeep(content, changes, { safeGet, safeSet });
}

this[PREVIOUS_CONTENT] = oldContent;

return this;
}
```

@snewcomer do you have any ideas on this case?

The only proposal I can think of now, is to allow to pass a `forceUpdate` or similar, to ignore `isValid` check.

Or, maybe I am missing point completely, and `changeset.get('name')` is actually an incorrect way to get "latest" value of a changeset?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.