ember-validated-form 5.1.0 → 5.1.1

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.
@@ -21,13 +21,26 @@
21
21
  <optgroup label={{optionGroup.groupName}}>
22
22
  {{#each optionGroup.options as |opt|}}
23
23
  {{#let
24
- (if @optionValuePath (get opt @optionValuePath) opt)
24
+ (if
25
+ (or @optionValuePath @optionTargetPath)
26
+ (get opt (or @optionValuePath @optionTargetPath))
27
+ opt
28
+ )
25
29
  as |optionValue|
26
30
  }}
27
31
  <option
28
32
  selected={{eq optionValue @value}}
29
33
  value={{optionValue}}
30
- >{{if @optionLabelPath (get opt @optionLabelPath) opt}}</option>
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>
31
44
  {{/let}}
32
45
  {{/each}}
33
46
  </optgroup>
@@ -35,14 +48,24 @@
35
48
  {{else}}
36
49
  {{#each @options as |opt|}}
37
50
  {{#let
38
- (if @optionValuePath (get opt @optionValuePath) opt)
51
+ (if
52
+ (or @optionValuePath @optionTargetPath)
53
+ (get opt (or @optionValuePath @optionTargetPath))
54
+ opt
55
+ )
39
56
  as |optionValue|
40
57
  }}
41
- <option selected={{eq optionValue @value}} value={{optionValue}}>{{if
58
+ <option selected={{eq optionValue @value}} value={{optionValue}}>{{#if
42
59
  @optionLabelPath
43
- (get opt @optionLabelPath)
44
- opt
45
- }}</option>
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>
46
69
  {{/let}}
47
70
  {{/each}}
48
71
  {{/if}}
@@ -69,10 +69,45 @@ export default class SelectComponent extends Component {
69
69
  return groups;
70
70
  }
71
71
 
72
+ findOption(target) {
73
+ const targetPath = this.args.optionTargetPath;
74
+ const valuePath = this.args.optionValuePath || targetPath;
75
+ let options = this.args.options;
76
+
77
+ //flatten pre grouped options
78
+ if (this.hasPreGroupedOptions) {
79
+ options = options.flatMap((group) => group.options);
80
+ }
81
+
82
+ // multi select
83
+ if (this.args.multiple) {
84
+ const selectedValues = Array.prototype.filter
85
+ .call(target.options, (option) => option.selected)
86
+ .map((option) => option.value);
87
+
88
+ const foundOptions = options.filter((item) =>
89
+ selectedValues.includes(`${valuePath ? item[valuePath] : item}`)
90
+ );
91
+ if (targetPath) {
92
+ return foundOptions.map((item) => item[targetPath]);
93
+ }
94
+ return foundOptions;
95
+ }
96
+
97
+ //single select
98
+ const foundOption = options.find(
99
+ (item) => `${valuePath ? item[valuePath] : item.value}` === target.value
100
+ );
101
+ if (targetPath) {
102
+ return foundOption[targetPath];
103
+ }
104
+ return foundOption;
105
+ }
106
+
72
107
  @action
73
108
  onUpdate(event) {
74
109
  if (this.args.update) {
75
- this.args.update(event.target.value);
110
+ this.args.update(this.findOption(event.target));
76
111
  }
77
112
  }
78
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-validated-form",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
4
4
  "description": "Easily create forms with client-side validations",
5
5
  "keywords": [
6
6
  "ember-addon",
@@ -41,7 +41,7 @@
41
41
  "devDependencies": {
42
42
  "@adfinis-sygroup/eslint-config": "1.5.0",
43
43
  "@adfinis-sygroup/semantic-release-config": "3.2.1",
44
- "@babel/core": "7.16.5",
44
+ "@babel/core": "7.16.7",
45
45
  "@babel/helper-create-regexp-features-plugin": "^7.16.7",
46
46
  "@babel/helper-environment-visitor": "^7.16.5",
47
47
  "@babel/plugin-proposal-decorators": "^7.16.7",