Skip to content

Commit

Permalink
backport of commit abd6324 (#22464)
Browse files Browse the repository at this point in the history
Co-authored-by: claire bontempo <68122737+hellobontempo@users.noreply.github.com>
  • Loading branch information
1 parent 1d716d7 commit 13da593
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog/22458.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: fixes model defaults overwriting input value when user tries to clear form input
```
3 changes: 2 additions & 1 deletion ui/lib/core/addon/components/form-field.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,9 @@
disabled={{and @attr.options.editDisabled (not @model.isNew)}}
autocomplete="off"
spellcheck="false"
value={{or (get @model this.valuePath) @attr.options.defaultValue}}
value={{get @model this.valuePath}}
{{on "change" this.onChangeWithEvent}}
{{on "input" this.onChangeWithEvent}}
{{on "keyup" this.handleKeyUp}}
class="input {{if this.validationError 'has-error-border'}}"
maxLength={{@attr.options.characterLimit}}
Expand Down
3 changes: 2 additions & 1 deletion ui/tests/integration/components/form-field-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module('Integration | Component | form field', function (hooks) {
};

const setup = async function (attr) {
const model = EmberObject.create({});
// ember sets model attrs from the defaultValue key, mimicking that behavior here
const model = EmberObject.create({ [attr.name]: attr.options?.defaultValue });
const spy = sinon.spy();
this.set('onChange', spy);
this.set('model', model);
Expand Down

0 comments on commit 13da593

Please sign in to comment.