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

<BsForm::Element> should respect @value argument #1406

Merged
merged 2 commits into from Jan 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 6 additions & 13 deletions addon/components/bs-form/element.js
Expand Up @@ -258,25 +258,18 @@ export default class FormElement extends FormGroup {
* @public
*/
get value() {
assert(
'You can not set both property and value on a form element',
isBlank(this.args.property) || isBlank(this.args.value)
);

if (this.args.property && this.args.model) {
return get(this.args.model, this.args.property);
}
return this._value;
}

set value(value) {
assert('You cannot set both property and value on a form element', isBlank(this.args.property));

this._value = value;
return this.args.value;
}

/**
* Cache for value
* @type {null}
* @private
*/
@tracked _value = null;

/**
The property name of the form element's `model` (by default the `model` of its parent `Components.Form`) that this
form element should represent. The control element's value will automatically be bound to the model property's
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/components/bs-form/element-test.js
Expand Up @@ -824,6 +824,22 @@ module('Integration | Component | bs-form/element', function (hooks) {
);
});

test('it can change a value instead of a property', async function (assert) {
this.set('update', (name) => this.set('name', name));
this.set('name', 'Tomster');

await render(hbs`
<BsForm::Element @onChange={{this.update}} @value={{this.name}} />
`);

assert.dom('input').hasValue('Tomster');

await fillIn('input', 'Zoey');

assert.dom('input').hasValue('Zoey');
assert.equal(this.name, 'Zoey');
});

// test for size property here to prevent regression of https://github.com/kaliber5/ember-bootstrap/issues/492
testBS3('support size classes', async function (assert) {
await render(hbs`<BsForm::Element @size="lg" />`);
Expand Down