ember-validated-form 5.2.1 → 5.2.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [5.2.2](https://github.com/adfinis-sygroup/ember-validated-form/compare/v5.2.1...v5.2.2) (2022-02-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * select support for plain options ([#747](https://github.com/adfinis-sygroup/ember-validated-form/issues/747)) ([a58e26d](https://github.com/adfinis-sygroup/ember-validated-form/commit/a58e26ddcd46ec5328c3bb5351bafc7781eacdbd))
7
+
1
8
  ## [5.2.1](https://github.com/adfinis-sygroup/ember-validated-form/compare/v5.2.0...v5.2.1) (2022-02-09)
2
9
 
3
10
 
@@ -20,53 +20,17 @@
20
20
  {{#each this.optionGroups as |optionGroup|}}
21
21
  <optgroup label={{optionGroup.groupName}}>
22
22
  {{#each optionGroup.options as |opt|}}
23
- {{#let
24
- (if
25
- (or @optionValuePath @optionTargetPath)
26
- (get opt (or @optionValuePath @optionTargetPath))
27
- opt
28
- )
29
- as |optionValue|
30
- }}
31
- <option
32
- selected={{eq optionValue @value}}
33
- value={{optionValue}}
34
- >{{#if @optionLabelPath}}
35
- {{get opt @optionLabelPath}}
36
- {{else if @optionValuePath}}
37
- {{get opt @optionValuePath}}
38
- {{else if @optionTargetPath}}
39
- {{get opt @optionTargetPath}}
40
- {{else}}
41
- {{opt}}
42
- {{/if}}
43
- </option>
44
- {{/let}}
23
+ <option selected={{eq opt.id @value}} value={{opt.id}}>
24
+ {{opt.label}}
25
+ </option>
45
26
  {{/each}}
46
27
  </optgroup>
47
28
  {{/each}}
48
29
  {{else}}
49
- {{#each @options as |opt|}}
50
- {{#let
51
- (if
52
- (or @optionValuePath @optionTargetPath)
53
- (get opt (or @optionValuePath @optionTargetPath))
54
- opt
55
- )
56
- as |optionValue|
57
- }}
58
- <option selected={{eq optionValue @value}} value={{optionValue}}>{{#if
59
- @optionLabelPath
60
- }}
61
- {{get opt @optionLabelPath}}
62
- {{else if @optionValuePath}}
63
- {{get opt @optionValuePath}}
64
- {{else if @optionTargetPath}}
65
- {{get opt @optionTargetPath}}
66
- {{else}}
67
- {{opt}}
68
- {{/if}}</option>
69
- {{/let}}
30
+ {{#each this.normalizedOptions as |opt|}}
31
+ <option selected={{eq opt.id @value}} value={{opt.id}}>
32
+ {{opt.label}}
33
+ </option>
70
34
  {{/each}}
71
35
  {{/if}}
72
36
  </select>
@@ -38,6 +38,23 @@ export default class SelectComponent extends Component {
38
38
  return this.hasPreGroupedOptions || this.args.groupLabelPath;
39
39
  }
40
40
 
41
+ get normalizedOptions() {
42
+ // normalize options to common data structure, only for rendering
43
+ return this.args.options.map((opt) => this.normalize(opt));
44
+ }
45
+
46
+ normalize(option) {
47
+ if (typeof option !== "object") {
48
+ return { id: option, label: option };
49
+ }
50
+ const valuePath = this.args.optionValuePath ?? this.args.optionTargetPath;
51
+ const labelPath = this.args.optionLabelPath;
52
+ return {
53
+ id: valuePath ? option[valuePath] : option.id,
54
+ label: labelPath ? option[labelPath] : option.label,
55
+ };
56
+ }
57
+
41
58
  get optionGroups() {
42
59
  const groupLabelPath = this.args.groupLabelPath;
43
60
  if (!groupLabelPath) {
@@ -60,7 +77,7 @@ export default class SelectComponent extends Component {
60
77
  groups.pushObject(group);
61
78
  }
62
79
 
63
- group.options.pushObject(item);
80
+ group.options.pushObject(this.normalize(item));
64
81
  } else {
65
82
  groups.pushObject(item);
66
83
  }
@@ -72,6 +89,17 @@ export default class SelectComponent extends Component {
72
89
  findOption(target) {
73
90
  const targetPath = this.args.optionTargetPath;
74
91
  const valuePath = this.args.optionValuePath || targetPath;
92
+
93
+ const getValue = (item) => {
94
+ if (valuePath) {
95
+ return String(item[valuePath]);
96
+ }
97
+ if (typeof item === "object") {
98
+ return String(item.id);
99
+ }
100
+ return String(item);
101
+ };
102
+
75
103
  let options = this.args.options;
76
104
 
77
105
  //flatten pre grouped options
@@ -85,9 +113,9 @@ export default class SelectComponent extends Component {
85
113
  .call(target.options, (option) => option.selected)
86
114
  .map((option) => option.value);
87
115
 
88
- const foundOptions = options.filter((item) =>
89
- selectedValues.includes(`${valuePath ? item[valuePath] : item}`)
90
- );
116
+ const foundOptions = options.filter((item) => {
117
+ return selectedValues.includes(getValue(item));
118
+ });
91
119
  if (targetPath) {
92
120
  return foundOptions.map((item) => item[targetPath]);
93
121
  }
@@ -95,9 +123,7 @@ export default class SelectComponent extends Component {
95
123
  }
96
124
 
97
125
  //single select
98
- const foundOption = options.find(
99
- (item) => `${valuePath ? item[valuePath] : item.value}` === target.value
100
- );
126
+ const foundOption = options.find((item) => getValue(item) === target.value);
101
127
  if (targetPath) {
102
128
  return foundOption[targetPath];
103
129
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-validated-form",
3
- "version": "5.2.1",
3
+ "version": "5.2.2",
4
4
  "description": "Easily create forms with client-side validations",
5
5
  "keywords": [
6
6
  "ember-addon",
@@ -41,16 +41,10 @@
41
41
  "devDependencies": {
42
42
  "@adfinis-sygroup/eslint-config": "1.5.0",
43
43
  "@adfinis-sygroup/semantic-release-config": "3.4.0",
44
- "@babel/core": "7.16.12",
45
- "@babel/helper-create-regexp-features-plugin": "^7.16.7",
46
- "@babel/helper-environment-visitor": "^7.16.7",
47
- "@babel/plugin-proposal-decorators": "^7.16.7",
48
- "@babel/plugin-transform-modules-amd": "^7.16.7",
49
- "@babel/preset-env": "^7.16.11",
50
44
  "@ember/optional-features": "2.0.0",
51
45
  "@ember/test-helpers": "2.6.0",
52
- "@embroider/test-setup": "0.45.0",
53
- "@fortawesome/ember-fontawesome": "0.2.3",
46
+ "@embroider/test-setup": "1.1.0",
47
+ "@fortawesome/ember-fontawesome": "0.3.1",
54
48
  "@fortawesome/free-solid-svg-icons": "5.15.4",
55
49
  "@glimmer/component": "1.0.4",
56
50
  "@glimmer/tracking": "1.0.4",
@@ -59,18 +53,17 @@
59
53
  "ember-changeset": "4.0.0-beta.2",
60
54
  "ember-changeset-validations": "4.0.0-beta.2",
61
55
  "ember-cli": "3.28.1",
62
- "ember-cli-addon-docs": "4.2.1",
56
+ "ember-cli-addon-docs": "4.2.2",
63
57
  "ember-cli-dependency-checker": "3.2.0",
64
58
  "ember-cli-deploy": "1.0.2",
65
59
  "ember-cli-deploy-build": "2.0.0",
66
60
  "ember-cli-deploy-git": "1.3.4",
67
61
  "ember-cli-deploy-git-ci": "1.0.1",
68
62
  "ember-cli-inject-live-reload": "2.1.0",
69
- "ember-cli-release": "1.0.0-beta.2",
70
63
  "ember-cli-sri": "2.1.1",
71
64
  "ember-cli-terser": "4.0.2",
72
65
  "ember-cli-test-loader": "3.0.0",
73
- "ember-concurrency": "2.2.0",
66
+ "ember-concurrency": "2.2.1",
74
67
  "ember-data": "3.28.3",
75
68
  "ember-disable-prototype-extensions": "1.1.3",
76
69
  "ember-load-initializers": "2.1.2",
@@ -91,19 +84,17 @@
91
84
  "eslint-plugin-prettier": "4.0.0",
92
85
  "eslint-plugin-qunit": "6.2.0",
93
86
  "husky": "7.0.4",
94
- "lint-staged": "11.2.0",
87
+ "lint-staged": "12.3.3",
95
88
  "loader.js": "4.7.0",
96
89
  "npm-run-all": "4.1.5",
97
90
  "prettier": "2.5.1",
98
91
  "qunit": "2.17.2",
99
92
  "qunit-dom": "2.0.0",
100
- "webpack": "5.67.0"
93
+ "webpack": "5.68.0"
101
94
  },
102
95
  "resolutions": {
103
- "graceful-fs": ">=4.2.0",
104
- "@embroider/macros": "^1.0.0",
105
- "@embroider/core": "^1.0.0",
106
- "@embroider/util": "^1.0.0"
96
+ "@embroider/macros": "^1.1.0",
97
+ "@embroider/util": "^1.1.0"
107
98
  },
108
99
  "engines": {
109
100
  "node": "12.* || 14.* || >= 16"