Skip to content

Commit

Permalink
Merge pull request #24 from Gavant/enhance-submit-arg
Browse files Browse the repository at this point in the history
Enhance submit arg
  • Loading branch information
bakerac4 authored Jan 11, 2023
2 parents 9bc0b84 + 6f4af1b commit 2eab857
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 48 deletions.
4 changes: 2 additions & 2 deletions ember-validations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"@babel/runtime": "^7.16.7",
"@ember/render-modifiers": "^2.0.4",
"@embroider/addon-dev": "^1.7.1",
"@glint/core": "^0.9.2",
"@glint/environment-ember-loose": "^0.9.2",
"@glint/core": "^0.9.7",
"@glint/environment-ember-loose": "^0.9.7",
"@rollup/plugin-babel": "^5.3.1",
"@types/ember-data__model": "^4.0.0",
"@types/ember-resolver": "^5.0.11",
Expand Down
4 changes: 2 additions & 2 deletions 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>[]] | [C]) => void;
submit: (parent: C, children?: GenericChangeset<any>[]) => void;
}

export type BoundInputValidator<C extends GenericChangeset<V>, V = ValueForChangeset<C>> = WithBoundArgs<
Expand Down Expand Up @@ -118,7 +118,7 @@ export default class FormValidator<C extends GenericChangeset<V>, V = ValueForCh

try {
await all(validations);
return this.args?.submit([ownChangeset, children.changesets]);
return this.args?.submit(ownChangeset, children.changesets);
} catch (error) {
this.showAllValidationFields = true;
this.childValidators.forEach((item) => {
Expand Down
17 changes: 3 additions & 14 deletions test-app/app/controllers/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,14 @@ import { action } from '@ember/object';

import { GenericChangeset } from '@gavant/ember-validations/utilities/create-changeset';

import Application, { RouteModel } from 'test-app/routes/application';
import Application, { RouteModel, TestChangeset } from 'test-app/routes/application';

export default class ApplicationController extends Controller {
declare model: RouteModel<Application>;
declare childChangeset: GenericChangeset<{ foo: string }>;

@action
submitForm([parent, children]: [
GenericChangeset<{
name: null;
num: string;
radio: null;
nestedItem: {
much: {
wow: null;
};
};
}>,
[GenericChangeset<{ foo: string }>]
]) {
submitForm(parent: TestChangeset, children: [typeof this.childChangeset]) {
parent.name;
children[0].foo;
window.alert('submitted succesfully!');
Expand Down
15 changes: 13 additions & 2 deletions test-app/app/routes/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Route from '@ember/routing/route';

import { validateNumber, validatePresence } from 'ember-changeset-validations/validators';

import createChangeset from '@gavant/ember-validations/utilities/create-changeset';
import createChangeset, { GenericChangeset } from '@gavant/ember-validations/utilities/create-changeset';

import ApplicationController from 'test-app/controllers/application';

Expand All @@ -22,6 +22,17 @@ const Validations = {
const childValidations = {
foo: [validatePresence({ presence: true, ignoreBlank: true })]
};

export type TestChangeset = GenericChangeset<{
name: null;
num: string;
radio: null;
nestedItem: {
much: {
wow: null;
};
};
}>;
export default class Application extends Route {
validations = Validations;

Expand All @@ -39,7 +50,7 @@ export default class Application extends Route {
},
Validations
);
return changeset;
return changeset as TestChangeset;
}

setupController(controller: ApplicationController, model: RouteModel<Application>, transition: Transition) {
Expand Down
1 change: 1 addition & 0 deletions test-app/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<h2 id="title">
Welcome to Ember
</h2>

{{! template-lint-disable no-passed-in-event-handlers }}
<FormValidator @changeset={{this.model}} @submit={{this.submitForm}} as |changeset validator|>
<validator.input @errors={{changeset.error.name.validation}}>
Expand Down
6 changes: 3 additions & 3 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"@embroider/webpack": "^1.8.3",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"@glint/core": "^0.9.2",
"@glint/environment-ember-loose": "^0.9.2",
"@glint/core": "^0.9.7",
"@glint/environment-ember-loose": "^0.9.7",
"@types/ember-resolver": "^5.0.11",
"@types/ember__application": "^4.0.0",
"@types/ember__array": "^4.0.1",
Expand Down Expand Up @@ -98,7 +98,7 @@
"qunit": "^2.19.1",
"qunit-dom": "^2.0.0",
"sass": "^1.53.0",
"typescript": "^4.7.4",
"typescript": "^4.9.4",
"webpack": "^5.73.0"
},
"engines": {
Expand Down
55 changes: 30 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1645,50 +1645,50 @@
"@glimmer/interfaces" "^0.42.2"
"@glimmer/util" "^0.42.2"

"@glint/config@^0.9.4":
version "0.9.4"
resolved "https://registry.yarnpkg.com/@glint/config/-/config-0.9.4.tgz#969b1d75e8c02ba92cca52e3e388aceadc150748"
integrity sha512-ip8lVWvdQYoxKQWessol9Lw8xwqp8y3DjKurXQqC9P9Hi2lnPQC2IoOAI565wRj8SnWrxBA1FCLVxtAWRGgADQ==
"@glint/config@^0.9.7":
version "0.9.7"
resolved "https://registry.yarnpkg.com/@glint/config/-/config-0.9.7.tgz#43077e9cd2743d3bb66f6c4670681c49644ac139"
integrity sha512-XkWIZ3fuOlcofUJUaJmRS57mVVNi+Af2HtrZkBXEOCh4+BNz2wclxv2WKvkhmtvLhEUOhHb5eU3gwI58SuwgXQ==
dependencies:
escape-string-regexp "^4.0.0"
minimatch "^3.0.4"
resolve "^1.17.0"
silent-error "^1.1.1"

"@glint/core@^0.9.2":
version "0.9.4"
resolved "https://registry.yarnpkg.com/@glint/core/-/core-0.9.4.tgz#147b77313f8841948390c86298ae501891408e76"
integrity sha512-7n7nUV/kbRQ6y5AhWyO2NO1J79/h3zaBn2BJ1NXaguUvQY70/YvM15CeA4JfsrFjR8Yr2Y175QfP0Ug4MSD89Q==
"@glint/core@^0.9.7":
version "0.9.7"
resolved "https://registry.yarnpkg.com/@glint/core/-/core-0.9.7.tgz#887dbdfa10d89702549de36197cc2eb0783a5c86"
integrity sha512-1YLHNRnuYI1dDUKWq/ue4JqiBt6TVR8e7VQJWy37CKB0tiBhWw/FPvr7/S7XbUxCt6KHO0Kl0x/eqLunu3WiQw==
dependencies:
"@glint/config" "^0.9.4"
"@glint/transform" "^0.9.4"
"@glint/config" "^0.9.7"
"@glint/transform" "^0.9.7"
resolve "^1.17.0"
uuid "^8.3.2"
vscode-languageserver "^8.0.1"
vscode-languageserver-textdocument "^1.0.5"
vscode-uri "^3.0.2"
yargs "^17.5.1"

"@glint/environment-ember-loose@^0.9.2":
version "0.9.4"
resolved "https://registry.yarnpkg.com/@glint/environment-ember-loose/-/environment-ember-loose-0.9.4.tgz#e95d1c64c0ab9866b8c8d46c590f3b915171eb31"
integrity sha512-70S8BwpfoOuoGRUvmsIF1be5vmYhzVzSnXRraa0UG6ZJm4WyrP1OqJEdl5sXTsKLsF/Gp8Fb5hc3dibP4GluNw==
"@glint/environment-ember-loose@^0.9.7":
version "0.9.7"
resolved "https://registry.yarnpkg.com/@glint/environment-ember-loose/-/environment-ember-loose-0.9.7.tgz#8d27e93d6bd3afd59c46acad27a2c3130045dee0"
integrity sha512-MlCGZtB1Clp4vQWIm2APSnCm7nL8wVhFMOhVy2qzpV0nfLyg3pcN9CQHNpfdJvCydBB72cA4/ahPj7VEFL6xsg==
dependencies:
"@glint/config" "^0.9.4"
"@glint/template" "^0.9.4"
"@glint/config" "^0.9.7"
"@glint/template" "^0.9.7"

"@glint/template@^0.9.4":
version "0.9.4"
resolved "https://registry.yarnpkg.com/@glint/template/-/template-0.9.4.tgz#b1df5f379d569169abd26a3cf927a2510ea2fd7f"
integrity sha512-MiIcFyTT7SeXhkv0WK4/s/LW9Go1E2FGf8xu+4/1PeSPfSgAbEgRqIXHdtIreeFQhVrAwFFGff/+eHZkRgZWsA==
"@glint/template@^0.9.7":
version "0.9.7"
resolved "https://registry.yarnpkg.com/@glint/template/-/template-0.9.7.tgz#8736f357482841962bc66e75831f189f33677165"
integrity sha512-MCp8GxQDIbH8ZzfNxHhVqCSKlydBgQfBEwJLDpN81lgFRCldSDPueIbk8sz3EhpGiZJVdNQbpGeYIDsUXe1ocg==

"@glint/transform@^0.9.4":
version "0.9.4"
resolved "https://registry.yarnpkg.com/@glint/transform/-/transform-0.9.4.tgz#5350901b2b840dccbc160349fe88f9486002ecab"
integrity sha512-RgK+Rm2fs+djH5jur5KGTcOTWMoPMJx1GB/6ksIXBDq8jA4l4V0ZKZR/GQ5B2NBlfzf7UqWPRb0LNff7grAVHg==
"@glint/transform@^0.9.7":
version "0.9.7"
resolved "https://registry.yarnpkg.com/@glint/transform/-/transform-0.9.7.tgz#01c60249c1fe6663955d2acd2cf7625a551fb3f3"
integrity sha512-vd0th+Zo4cirYepASpC0fE0ZCqAcI9Y6qHYE0xi4+MY05bFRxBr7Q9ggDoWk+slynTyUrVgzCCeazAYOlZsYcg==
dependencies:
"@glimmer/syntax" "^0.84.2"
"@glint/config" "^0.9.4"
"@glint/config" "^0.9.7"

"@handlebars/parser@~2.0.0":
version "2.0.0"
Expand Down Expand Up @@ -13511,6 +13511,11 @@ typescript@^4.7.4:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==

typescript@^4.9.4:
version "4.9.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.4.tgz#a2a3d2756c079abda241d75f149df9d561091e78"
integrity sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==

ua-parser-js@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.2.tgz#e2976c34dbfb30b15d2c300b2a53eac87c57a775"
Expand Down

0 comments on commit 2eab857

Please sign in to comment.