Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: fix default values resetting form inputs #22458

Merged
merged 5 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -306,8 +306,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}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ember sets the @model attribute with whatever the defaultValue is - so this extra logic was redundant and causing overwrites docs

{{on "change" this.onChangeWithEvent}}
{{on "input" this.onChangeWithEvent}}
Copy link
Contributor Author

@hellobontempo hellobontempo Aug 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required for model validations that happen when the input changes (not just on submit)

{{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 @@ -26,7 +26,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