Skip to content

Commit c40ffaf

Browse files
committed
Don't error when control element is missing
1 parent d5e8d22 commit c40ffaf

File tree

2 files changed

+18
-1
lines changed
  • packages

2 files changed

+18
-1
lines changed

packages/ember-bootstrap-constraint-validations/src/components/bs-form/element.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class BsFormElement extends BaseBsFormElement {
2424

2525
get errors() {
2626
let { controlElement, _invalidateErrors } = this;
27-
return controlElement?.validity.valid
27+
return !controlElement || controlElement.validity.valid
2828
? []
2929
: [controlElement.validationMessage];
3030
}

packages/test-app/tests/integration/components/bs-form-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,21 @@ module('Integration | Component | bs-form', function (hooks) {
155155
.dom('input')
156156
.hasClass('is-valid', 'validation error is shown after focus out');
157157
});
158+
159+
test('does not throw when control element is not available', async function (assert) {
160+
assert.expect(0);
161+
this.set('model', {});
162+
163+
await render(hbs`
164+
<BsForm @model={{this.model}} as |form|>
165+
<form.element @label="First name" @property="firstname" as |el|>
166+
</form.element>
167+
<form.element @label="last name" @property="lastname" as |el|>
168+
<el.control required/>
169+
</form.element>
170+
</BsForm>
171+
`);
172+
173+
await triggerEvent('form', 'submit');
174+
});
158175
});

0 commit comments

Comments
 (0)