Skip to content

Commit

Permalink
Merge pull request #23 from Gavant/allow-optional-children-submit
Browse files Browse the repository at this point in the history
Allow for optional children validators
  • Loading branch information
bakerac4 authored Jan 10, 2023
2 parents 615d358 + da9f005 commit 1c68a2b
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 1,343 deletions.
2 changes: 0 additions & 2 deletions ember-validations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"@glint/environment-ember-loose": "^0.9.2",
"@rollup/plugin-babel": "^5.3.1",
"@types/ember-data__model": "^4.0.0",
"@types/ember-qunit": "^5.0.0",
"@types/ember-resolver": "^5.0.11",
"@types/ember__application": "^4.0.0",
"@types/ember__array": "^4.0.1",
Expand All @@ -71,7 +70,6 @@
"@types/ember__string": "^3.0.9",
"@types/ember__template": "^4.0.0",
"@types/ember__test": "^4.0.0",
"@types/ember__test-helpers": "^2.6.1",
"@types/ember__utils": "^4.0.0",
"@typescript-eslint/eslint-plugin": "^5.18.0",
"@typescript-eslint/parser": "^5.18.0",
Expand Down
2 changes: 1 addition & 1 deletion ember-validations/src/components/form-validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import FormValidatorChild from './child';

interface FormValidatorArgs<C extends GenericChangeset<V>, V = ValueForChangeset<C>> {
changeset: C;
submit: (changesets: [C, GenericChangeset<any>[]]) => void;
submit: (changesets: [C, GenericChangeset<any>[]] | [C]) => void;
}

export type BoundInputValidator<C extends GenericChangeset<V>, V = ValueForChangeset<C>> = WithBoundArgs<
Expand Down
16 changes: 15 additions & 1 deletion test-app/app/controllers/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,21 @@ export default class ApplicationController extends Controller {
declare model: RouteModel<Application>;
declare childChangeset: GenericChangeset<{ foo: string }>;
@action
submitForm() {
submitForm([parent, children]: [
GenericChangeset<{
name: null;
num: string;
radio: null;
nestedItem: {
much: {
wow: null;
};
};
}>,
[GenericChangeset<{ foo: string }>]
]) {
parent.name;
children[0].foo;
window.alert('submitted succesfully!');
}

Expand Down
1 change: 1 addition & 0 deletions test-app/config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = async function () {
name: 'ember-lts-3.24',
npm: {
devDependencies: {
'ember-qunit': '^5.1.4',
'ember-source': '~3.24.3'
}
}
Expand Down
8 changes: 3 additions & 5 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"devDependencies": {
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.7.0",
"@ember/test-helpers": "^2.9.3",
"@embroider/compat": "^1.8.3",
"@embroider/core": "^1.8.3",
"@embroider/test-setup": "^1.7.1",
Expand All @@ -36,7 +36,6 @@
"@glimmer/tracking": "^1.1.2",
"@glint/core": "^0.9.2",
"@glint/environment-ember-loose": "^0.9.2",
"@types/ember-qunit": "^5.0.0",
"@types/ember-resolver": "^5.0.11",
"@types/ember__application": "^4.0.0",
"@types/ember__array": "^4.0.1",
Expand All @@ -53,7 +52,6 @@
"@types/ember__string": "^3.0.9",
"@types/ember__template": "^4.0.0",
"@types/ember__test": "^4.0.0",
"@types/ember__test-helpers": "^2.6.1",
"@types/ember__utils": "^4.0.0",
"@types/htmlbars-inline-precompile": "^3.0.0",
"@types/qunit": "^2.19.1",
Expand Down Expand Up @@ -82,8 +80,8 @@
"ember-fetch": "^8.1.1",
"ember-load-initializers": "^2.1.2",
"ember-page-title": "^7.0.0",
"ember-qunit": "^5.1.5",
"ember-resolver": "^8.0.3",
"ember-qunit": "^6.1.1",
"ember-resolver": "^8.0.0",
"ember-source": "~4.4.0",
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^4.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ module('Integration | Component | changeset-input', function (hooks) {
class="form-control"
autocomplete="off" />`);

assert.strictEqual(this.element.textContent?.trim(), '');
assert.dom().hasNoText();
});
});
4 changes: 2 additions & 2 deletions test-app/tests/integration/components/form-validator-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module('Integration | Component | form-validator', function (hooks) {

await render(hbs`{{form-validator}}`);

assert.strictEqual(this.element.textContent?.trim(), '');
assert.dom().hasNoText();

// Template block usage:
await render(hbs`
Expand All @@ -23,6 +23,6 @@ module('Integration | Component | form-validator', function (hooks) {
{{/form-validator}}
`);

assert.strictEqual(this.element.textContent?.trim(), 'template block text');
assert.dom().containsText('template block text');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ module('Integration | Component | form-validator/child', function (hooks) {
<validator.child @changeset={{this.childChangeset}} />
</FormValidator>`
);
let element = this.element.textContent;
assert.strictEqual(element?.trim(), '');
assert.dom().hasNoText();

// Template block usage:
await render(hbs`
Expand All @@ -30,7 +29,6 @@ module('Integration | Component | form-validator/child', function (hooks) {
</FormValidator>
`);

element = this.element.textContent;
assert.strictEqual(element?.trim(), 'template block text');
assert.dom().containsText('template block text');
});
});
5 changes: 2 additions & 3 deletions test-app/tests/integration/components/input-validator-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module('Integration | Component | input-validator', function (hooks) {
<FormValidator @changeset={{this.changeset}} as |changeset validator|>
<validator.input @errors={{changeset.error.name.validation}} @fieldLabel="Name" @label={{true}} />
</FormValidator>`);
let element = this.element.textContent;
assert.strictEqual(element?.trim(), '');

assert.dom().hasNoText();

// Template block usage:
await render(hbs`
Expand All @@ -28,7 +28,6 @@ module('Integration | Component | input-validator', function (hooks) {
</validator.input>
</FormValidator>`);

element = this.element.textContent;
assert.dom('input').exists();
});
});
Loading

0 comments on commit 1c68a2b

Please sign in to comment.