ember-validated-form 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.husky/commit-msg CHANGED
@@ -1 +1,7 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ # skip in CI
5
+ [ -n "$CI" ] && exit 0
6
+
1
7
  yarn commitlint --edit $1
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ # skip in CI
5
+ [ -n "$CI" ] && exit 0
6
+
7
+ # lint only staged files
8
+ yarn lint-staged
@@ -1,9 +1,9 @@
1
1
  {{#let
2
2
  (component
3
3
  this.buttonComponent
4
- onClick=@action
5
- loading=@loading
6
- disabled=@disabled
4
+ onClick=this.click
5
+ loading=this.loading
6
+ disabled=(or @disabled this.loading)
7
7
  label=@label
8
8
  type=@type
9
9
  )
@@ -1,7 +1,55 @@
1
+ import { action } from "@ember/object";
1
2
  import Component from "@glimmer/component";
3
+ import { tracked } from "@glimmer/tracking";
4
+ import { resolve } from "rsvp";
2
5
 
3
6
  import themedComponent from "../-private/themed-component";
4
7
 
8
+ const ON_CLICK = "on-click";
9
+ const ON_INVALID_CLICK = "on-invalid-click";
5
10
  export default class ValidatedButtonComponent extends Component {
6
11
  @themedComponent("validated-button/button") buttonComponent;
12
+
13
+ @tracked _loading;
14
+
15
+ get loading() {
16
+ return this.args.loading || this._loading;
17
+ }
18
+
19
+ @action
20
+ async click(event) {
21
+ // handle only clicks for custom buttons
22
+ // everything else is handled by the validated form itself
23
+ if (this.args.type !== "button") {
24
+ return this.args.action(event);
25
+ }
26
+
27
+ event.preventDefault();
28
+ const model = this.args.model;
29
+
30
+ if (!model || !model.validate) {
31
+ this.runCallback(ON_CLICK);
32
+ return;
33
+ }
34
+
35
+ await model.validate();
36
+
37
+ if (model.get("isInvalid")) {
38
+ this.runCallback(ON_INVALID_CLICK);
39
+ } else {
40
+ this.runCallback(ON_CLICK);
41
+ }
42
+ }
43
+
44
+ runCallback(callbackProp) {
45
+ const callback = this.args[callbackProp];
46
+ if (typeof callback !== "function") {
47
+ return;
48
+ }
49
+
50
+ this._loading = true;
51
+ resolve(callback(this.args.model)).finally(() => {
52
+ this._loading = false;
53
+ });
54
+ }
7
55
  }
@@ -16,6 +16,13 @@
16
16
  label="Save"
17
17
  action=this.submit
18
18
  )
19
+ button=(component
20
+ "validated-button"
21
+ type="button"
22
+ loading=this.loading
23
+ label="Action"
24
+ model=@model
25
+ )
19
26
  )
20
27
  }}
21
28
  </form>
@@ -1,4 +1,5 @@
1
1
  import { action } from "@ember/object";
2
+ import { scheduleOnce } from "@ember/runloop";
2
3
  import Component from "@glimmer/component";
3
4
  import { tracked } from "@glimmer/tracking";
4
5
  import { resolve } from "rsvp";
@@ -15,10 +16,14 @@ export default class ValidatedFormComponent extends Component {
15
16
  super(...args);
16
17
 
17
18
  if (this.args.model && this.args.model.validate) {
18
- this.args.model.validate();
19
+ scheduleOnce("actions", this, "validateModel", this.args.model);
19
20
  }
20
21
  }
21
22
 
23
+ validateModel(model) {
24
+ model.validate();
25
+ }
26
+
22
27
  @action
23
28
  async submit(event) {
24
29
  event.preventDefault();
@@ -3,7 +3,7 @@ import Component from "@glimmer/component";
3
3
 
4
4
  export default class CheckboxGroupComponent extends Component {
5
5
  @action
6
- onUpdate(event, key) {
6
+ onUpdate(key, event) {
7
7
  event.preventDefault();
8
8
 
9
9
  const value = this.value || [];
@@ -1,17 +1,49 @@
1
- {{! template-lint-disable no-passed-in-event-handlers }}
2
- <OneWaySelect
3
- @value={{@value}}
4
- @options={{@options}}
5
- @optionLabelPath={{@optionLabelPath}}
6
- @optionValuePath={{@optionValuePath}}
7
- @optionTargetPath={{@optionTargetPath}}
8
- @name={{@name}}
9
- @id={{@inputId}}
10
- @class={{this.class}}
11
- @update={{@update}}
12
- @focusOut={{@setDirty}}
13
- @includeBlank={{@includeBlank}}
14
- @disabled={{@disabled}}
15
- @multiple={{@multiple}}
16
- @promptIsSelectable={{or @promptIsSelectable false}}
17
- />
1
+ <select
2
+ class={{this.class}}
3
+ ...attributes
4
+ name={{@name}}
5
+ id={{@inpudId}}
6
+ disabled={{@disabled}}
7
+ multiple={{@multiple}}
8
+ {{on "change" this.onUpdate}}
9
+ {{on "blur" this.onBlur}}
10
+ >
11
+ {{#if (or @prompt @includeBlank)}}
12
+ <option
13
+ value=""
14
+ disabled={{not @promptIsSelectable}}
15
+ selected={{not @value}}
16
+ >{{or @prompt @includeBlank}}</option>
17
+ {{/if}}
18
+
19
+ {{#if this.hasGrouping}}
20
+ {{#each this.optionGroups as |optionGroup|}}
21
+ <optgroup label={{optionGroup.groupName}}>
22
+ {{#each optionGroup.options as |opt|}}
23
+ {{#let
24
+ (if @optionValuePath (get opt @optionValuePath) opt)
25
+ as |optionValue|
26
+ }}
27
+ <option
28
+ selected={{eq optionValue @value}}
29
+ value={{optionValue}}
30
+ >{{if @optionLabelPath (get opt @optionLabelPath) opt}}</option>
31
+ {{/let}}
32
+ {{/each}}
33
+ </optgroup>
34
+ {{/each}}
35
+ {{else}}
36
+ {{#each @options as |opt|}}
37
+ {{#let
38
+ (if @optionValuePath (get opt @optionValuePath) opt)
39
+ as |optionValue|
40
+ }}
41
+ <option selected={{eq optionValue @value}} value={{optionValue}}>{{if
42
+ @optionLabelPath
43
+ (get opt @optionLabelPath)
44
+ opt
45
+ }}</option>
46
+ {{/let}}
47
+ {{/each}}
48
+ {{/if}}
49
+ </select>
@@ -1,4 +1,85 @@
1
+ import { A as emberArray, isArray } from "@ember/array";
2
+ import { deprecate } from "@ember/debug";
3
+ import EmberObject, { action, get } from "@ember/object";
1
4
  import Component from "@glimmer/component";
2
5
 
3
- // eslint-disable-next-line ember/no-empty-glimmer-component-classes
4
- export default class SelectComponent extends Component {}
6
+ /**
7
+ * This component is heavily inspired by the ember-one-way-select addon.
8
+ * https://github.com/DockYard/ember-one-way-select
9
+ * Our implementation is slightly simpler, since it does not support
10
+ * the block syntax for options.
11
+ */
12
+
13
+ export default class SelectComponent extends Component {
14
+ constructor(...args) {
15
+ super(...args);
16
+
17
+ if (this.args.includeBlank) {
18
+ deprecate(
19
+ "The `includeBlank` property is deprecated. Please use `prompt` instead.",
20
+ false,
21
+ {
22
+ id: "ember-validated-form:NoMoreincludeBlank",
23
+ until: "6.0.0",
24
+ since: "5.1.0",
25
+ url: "https://github.com/adfinis-sygroup/ember-validated-form/releases/tag/v5.1.0",
26
+ }
27
+ );
28
+ }
29
+ }
30
+
31
+ get hasPreGroupedOptions() {
32
+ return (
33
+ this.args.options[0]?.groupName && isArray(this.args.options[0]?.options)
34
+ );
35
+ }
36
+
37
+ get hasGrouping() {
38
+ return this.hasPreGroupedOptions || this.args.groupLabelPath;
39
+ }
40
+
41
+ get optionGroups() {
42
+ const groupLabelPath = this.args.groupLabelPath;
43
+ if (!groupLabelPath) {
44
+ return this.args.options;
45
+ }
46
+ const groups = emberArray();
47
+
48
+ this.args.options.forEach((item) => {
49
+ const label = get(item, groupLabelPath);
50
+
51
+ if (label) {
52
+ let group = groups.findBy("groupName", label);
53
+
54
+ if (!group) {
55
+ group = EmberObject.create({
56
+ groupName: label,
57
+ options: emberArray(),
58
+ });
59
+
60
+ groups.pushObject(group);
61
+ }
62
+
63
+ group.options.pushObject(item);
64
+ } else {
65
+ groups.pushObject(item);
66
+ }
67
+ });
68
+
69
+ return groups;
70
+ }
71
+
72
+ @action
73
+ onUpdate(event) {
74
+ if (this.args.update) {
75
+ this.args.update(event.target.value);
76
+ }
77
+ }
78
+
79
+ @action
80
+ onBlur(event) {
81
+ if (this.args.setDirty) {
82
+ this.args.setDirty(event.target.value);
83
+ }
84
+ }
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-validated-form",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Easily create forms with client-side validations",
5
5
  "keywords": [
6
6
  "ember-addon",
@@ -29,27 +29,26 @@
29
29
  "start": "ember serve",
30
30
  "test": "npm-run-all lint test:*",
31
31
  "test:ember": "ember test",
32
- "test:ember-compatibility": "ember try:each"
33
- },
34
- "lint-staged": {
35
- "*.{js,json,css,md}": [
36
- "prettier --write",
37
- "git add"
38
- ]
32
+ "test:ember-compatibility": "ember try:each",
33
+ "prepare": "husky install"
39
34
  },
40
35
  "dependencies": {
41
36
  "ember-auto-import": "^2.2.0",
42
37
  "ember-cli-babel": "^7.26.6",
43
38
  "ember-cli-htmlbars": "^5.7.1",
44
- "ember-one-way-select": "^4.0.1",
45
39
  "ember-truth-helpers": "^3.0.0"
46
40
  },
47
41
  "devDependencies": {
48
- "@adfinis-sygroup/eslint-config": "1.4.2",
49
- "@adfinis-sygroup/semantic-release-config": "3.2.0",
50
- "@babel/core": "7.15.8",
42
+ "@adfinis-sygroup/eslint-config": "1.5.0",
43
+ "@adfinis-sygroup/semantic-release-config": "3.2.1",
44
+ "@babel/core": "7.16.5",
45
+ "@babel/helper-create-regexp-features-plugin": "^7.16.7",
46
+ "@babel/helper-environment-visitor": "^7.16.5",
47
+ "@babel/plugin-proposal-decorators": "^7.16.7",
48
+ "@babel/plugin-transform-modules-amd": "^7.16.7",
49
+ "@babel/preset-env": "^7.16.7",
51
50
  "@ember/optional-features": "2.0.0",
52
- "@ember/test-helpers": "2.5.0",
51
+ "@ember/test-helpers": "2.6.0",
53
52
  "@embroider/test-setup": "0.45.0",
54
53
  "@fortawesome/ember-fontawesome": "0.2.3",
55
54
  "@fortawesome/free-solid-svg-icons": "5.15.4",
@@ -60,7 +59,7 @@
60
59
  "ember-changeset": "3.15.0",
61
60
  "ember-changeset-validations": "3.16.0",
62
61
  "ember-cli": "3.28.1",
63
- "ember-cli-addon-docs": "4.0.3",
62
+ "ember-cli-addon-docs": "4.2.1",
64
63
  "ember-cli-dependency-checker": "3.2.0",
65
64
  "ember-cli-deploy": "1.0.2",
66
65
  "ember-cli-deploy-build": "2.0.0",
@@ -71,7 +70,7 @@
71
70
  "ember-cli-sri": "2.1.1",
72
71
  "ember-cli-terser": "4.0.2",
73
72
  "ember-cli-test-loader": "3.0.0",
74
- "ember-concurrency": "2.1.2",
73
+ "ember-concurrency": "2.2.0",
75
74
  "ember-data": "3.28.3",
76
75
  "ember-disable-prototype-extensions": "1.1.3",
77
76
  "ember-load-initializers": "2.1.2",
@@ -81,17 +80,17 @@
81
80
  "ember-resolver": "8.0.3",
82
81
  "ember-source": "3.28.1",
83
82
  "ember-source-channel-url": "3.0.0",
84
- "ember-template-lint": "3.9.0",
83
+ "ember-template-lint": "3.15.0",
85
84
  "ember-template-lint-plugin-prettier": "2.0.1",
86
85
  "ember-try": "1.4.0",
87
86
  "eslint": "7.32.0",
88
87
  "eslint-config-prettier": "8.3.0",
89
- "eslint-plugin-ember": "10.5.5",
90
- "eslint-plugin-import": "2.24.2",
88
+ "eslint-plugin-ember": "10.5.8",
89
+ "eslint-plugin-import": "2.25.3",
91
90
  "eslint-plugin-node": "11.1.0",
92
91
  "eslint-plugin-prettier": "4.0.0",
93
92
  "eslint-plugin-qunit": "6.2.0",
94
- "husky": "7.0.2",
93
+ "husky": "7.0.4",
95
94
  "lint-staged": "11.2.0",
96
95
  "loader.js": "4.7.0",
97
96
  "npm-run-all": "4.1.5",
@@ -116,6 +115,11 @@
116
115
  "release": {
117
116
  "extends": "@adfinis-sygroup/semantic-release-config"
118
117
  },
118
+ "lint-staged": {
119
+ "*.js": "eslint --cache --fix",
120
+ "*.hbs": "ember-template-lint --fix",
121
+ "*.{scss,graphql,json,md,yml}": "prettier --write"
122
+ },
119
123
  "commitlint": {
120
124
  "extends": [
121
125
  "@commitlint/config-conventional"
package/.husky/precommit DELETED
@@ -1 +0,0 @@
1
- yarn lint-staged