@frontile/changeset-form 0.12.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/LICENSE.md +9 -0
- package/README.md +37 -0
- package/addon/components/changeset-form/context/index.hbs +15 -0
- package/addon/components/changeset-form/fields/base.ts +71 -0
- package/addon/components/changeset-form/fields/checkbox-group.hbs +23 -0
- package/addon/components/changeset-form/fields/checkbox-group.ts +58 -0
- package/addon/components/changeset-form/fields/checkbox.hbs +15 -0
- package/addon/components/changeset-form/fields/checkbox.ts +56 -0
- package/addon/components/changeset-form/fields/input.hbs +22 -0
- package/addon/components/changeset-form/fields/input.ts +16 -0
- package/addon/components/changeset-form/fields/radio-group.hbs +18 -0
- package/addon/components/changeset-form/fields/radio-group.ts +20 -0
- package/addon/components/changeset-form/fields/radio.hbs +17 -0
- package/addon/components/changeset-form/fields/radio.ts +20 -0
- package/addon/components/changeset-form/fields/select.hbs +72 -0
- package/addon/components/changeset-form/fields/select.ts +43 -0
- package/addon/components/changeset-form/fields/textarea.hbs +22 -0
- package/addon/components/changeset-form/fields/textarea.ts +16 -0
- package/addon/components/changeset-form/index.hbs +23 -0
- package/addon/components/changeset-form/index.ts +71 -0
- package/app/components/changeset-form/context/index.js +1 -0
- package/app/components/changeset-form/fields/checkbox-group.js +1 -0
- package/app/components/changeset-form/fields/checkbox.js +1 -0
- package/app/components/changeset-form/fields/input.js +1 -0
- package/app/components/changeset-form/fields/radio-group.js +1 -0
- package/app/components/changeset-form/fields/radio.js +1 -0
- package/app/components/changeset-form/fields/select.js +1 -0
- package/app/components/changeset-form/fields/textarea.js +1 -0
- package/app/components/changeset-form.js +1 -0
- package/components/changeset-form/fields/base.d.ts +18 -0
- package/components/changeset-form/fields/checkbox-group.d.ts +15 -0
- package/components/changeset-form/fields/checkbox.d.ts +14 -0
- package/components/changeset-form/fields/input.d.ts +8 -0
- package/components/changeset-form/fields/radio-group.d.ts +8 -0
- package/components/changeset-form/fields/radio.d.ts +8 -0
- package/components/changeset-form/fields/select.d.ts +13 -0
- package/components/changeset-form/fields/textarea.d.ts +8 -0
- package/components/changeset-form/index.d.ts +22 -0
- package/config/environment.js +5 -0
- package/docs/changeset-form-usage-demo/demo.md +122 -0
- package/docs/changeset-form-usage.md +134 -0
- package/index.js +5 -0
- package/package.json +82 -0
- package/tsconfig.json +24 -0
- package/types/dummy/index.d.ts +0 -0
- package/types/ember-changeset-validations.d.ts +56 -0
- package/types/ember-power-select/test-support.d.ts +29 -0
- package/types/global.d.ts +6 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# @frontile/changeset-form
|
|
2
|
+
|
|
3
|
+
Integration between @frontile/forms package and [Changeset](https://github.com/poteto/ember-changeset).
|
|
4
|
+
|
|
5
|
+
## Compatibility
|
|
6
|
+
|
|
7
|
+
- Ember.js v3.16 or above
|
|
8
|
+
- Ember CLI v2.13 or above
|
|
9
|
+
- Node.js v10 or above
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
ember install @frontile/changeset-form
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Styles
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
// tailwind.config.js
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
theme: {
|
|
24
|
+
// ...
|
|
25
|
+
},
|
|
26
|
+
plugins: [require('@frontile/forms/tailwind')]
|
|
27
|
+
};
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Documentation
|
|
31
|
+
|
|
32
|
+
Visit [frontile.dev](https://frontile.dev/) to read the docs
|
|
33
|
+
and see live demos.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
This project is licensed under the [MIT License](LICENSE.md).
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{{yield
|
|
2
|
+
(hash
|
|
3
|
+
Input=(component "changeset-form/fields/input" changeset=@changeset)
|
|
4
|
+
Textarea=(component "changeset-form/fields/textarea" changeset=@changeset)
|
|
5
|
+
Select=(component "changeset-form/fields/select" changeset=@changeset)
|
|
6
|
+
Checkbox=(component "changeset-form/fields/checkbox" changeset=@changeset)
|
|
7
|
+
CheckboxGroup=(component
|
|
8
|
+
"changeset-form/fields/checkbox-group" changeset=@changeset
|
|
9
|
+
)
|
|
10
|
+
Radio=(component "changeset-form/fields/radio" changeset=@changeset)
|
|
11
|
+
RadioGroup=(component
|
|
12
|
+
"changeset-form/fields/radio-group" changeset=@changeset
|
|
13
|
+
)
|
|
14
|
+
)
|
|
15
|
+
}}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { BufferedChangeset } from 'ember-changeset/types';
|
|
3
|
+
import { assert } from '@ember/debug';
|
|
4
|
+
import { action } from '@ember/object';
|
|
5
|
+
import { later } from '@ember/runloop';
|
|
6
|
+
|
|
7
|
+
export interface BaseArgs {
|
|
8
|
+
changeset: BufferedChangeset;
|
|
9
|
+
fieldName: string;
|
|
10
|
+
errors?: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ValidationError {
|
|
14
|
+
key: string;
|
|
15
|
+
value: unknown;
|
|
16
|
+
validation: string[] | string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default class ChangesetFormFieldsBase<
|
|
20
|
+
T extends BaseArgs
|
|
21
|
+
> extends Component<T> {
|
|
22
|
+
constructor(owner: unknown, args: T) {
|
|
23
|
+
super(owner, args);
|
|
24
|
+
|
|
25
|
+
assert(
|
|
26
|
+
'<ChangesetForm> fields must receive @changeset',
|
|
27
|
+
typeof this.args.changeset !== 'undefined'
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
assert(
|
|
31
|
+
'<ChangesetForm> fields must receive @fieldName',
|
|
32
|
+
typeof this.args.fieldName !== 'undefined'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get value(): unknown {
|
|
37
|
+
return this.args.changeset.get(this.args.fieldName);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get errors(): string[] {
|
|
41
|
+
if (typeof this.args.errors !== 'undefined') {
|
|
42
|
+
return this.args.errors;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const fieldErrors = this.args.changeset.errors.filter((error) => {
|
|
46
|
+
return error.key === this.args.fieldName;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return fieldErrors.reduce(
|
|
50
|
+
(errors: string[], error: ValidationError): string[] => {
|
|
51
|
+
if (Array.isArray(error.validation)) {
|
|
52
|
+
return [...errors, ...error.validation];
|
|
53
|
+
} else {
|
|
54
|
+
return [...errors, error.validation];
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[]
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@action
|
|
62
|
+
async validate(): Promise<void> {
|
|
63
|
+
later(
|
|
64
|
+
this,
|
|
65
|
+
() => {
|
|
66
|
+
this.args.changeset.validate(this.args.fieldName);
|
|
67
|
+
},
|
|
68
|
+
1
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<FormCheckboxGroup
|
|
2
|
+
@onChange={{this.handleChange}}
|
|
3
|
+
@errors={{this.errors}}
|
|
4
|
+
|
|
5
|
+
@label={{@label}}
|
|
6
|
+
@hint={{@hint}}
|
|
7
|
+
@hasError={{@hasError}}
|
|
8
|
+
@hasSubmitted={{@hasSubmitted}}
|
|
9
|
+
@containerClass={{@containerClass}}
|
|
10
|
+
@size={{@size}}
|
|
11
|
+
@isInline={{@isInline}}
|
|
12
|
+
|
|
13
|
+
...attributes
|
|
14
|
+
as |Checkbox api|
|
|
15
|
+
>
|
|
16
|
+
{{yield (component "changeset-form/fields/checkbox"
|
|
17
|
+
_groupName=@groupName
|
|
18
|
+
_parentOnChange=api.onChange
|
|
19
|
+
changeset=@changeset
|
|
20
|
+
size=@size
|
|
21
|
+
)
|
|
22
|
+
}}
|
|
23
|
+
</FormCheckboxGroup>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { BufferedChangeset } from 'ember-changeset/types';
|
|
3
|
+
import { assert } from '@ember/debug';
|
|
4
|
+
import { action } from '@ember/object';
|
|
5
|
+
import { ValidationError } from './base';
|
|
6
|
+
|
|
7
|
+
interface ChangesetFormFieldsGroupArgs {
|
|
8
|
+
errors?: string[];
|
|
9
|
+
changeset: BufferedChangeset;
|
|
10
|
+
groupName?: string;
|
|
11
|
+
onChange?: (value: unknown, event: Event) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default class ChangesetFormFieldsCheckboxGroup extends Component<ChangesetFormFieldsGroupArgs> {
|
|
15
|
+
constructor(owner: unknown, args: ChangesetFormFieldsGroupArgs) {
|
|
16
|
+
super(owner, args);
|
|
17
|
+
|
|
18
|
+
assert(
|
|
19
|
+
'<ChangesetForm> fields must receive @changeset',
|
|
20
|
+
typeof this.args.changeset !== 'undefined'
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get errors(): string[] {
|
|
25
|
+
if (typeof this.args.errors !== 'undefined') {
|
|
26
|
+
return this.args.errors;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!this.args.groupName) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const fieldErrors = this.args.changeset.errors.filter((error) => {
|
|
34
|
+
return error.key === this.args.groupName;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return fieldErrors.reduce(
|
|
38
|
+
(errors: string[], error: ValidationError): string[] => {
|
|
39
|
+
return [...errors, ...error.validation];
|
|
40
|
+
},
|
|
41
|
+
[]
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@action async validate(): Promise<void> {
|
|
46
|
+
if (this.args.groupName) {
|
|
47
|
+
await this.args.changeset.validate(this.args.groupName);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@action handleChange(value: unknown, event: Event): void {
|
|
52
|
+
this.validate();
|
|
53
|
+
|
|
54
|
+
if (typeof this.args.onChange === 'function') {
|
|
55
|
+
this.args.onChange(value, event);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<FormCheckbox
|
|
2
|
+
@onChange={{this.handleChange}}
|
|
3
|
+
@checked={{this.value}}
|
|
4
|
+
@hint={{@hint}}
|
|
5
|
+
@name={{@name}}
|
|
6
|
+
@containerClass={{@containerClass}}
|
|
7
|
+
@size={{@size}}
|
|
8
|
+
...attributes
|
|
9
|
+
>
|
|
10
|
+
{{#if (has-block)}}
|
|
11
|
+
{{yield}}
|
|
12
|
+
{{else}}
|
|
13
|
+
{{@label}}
|
|
14
|
+
{{/if}}
|
|
15
|
+
</FormCheckbox>
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import Base, { BaseArgs, ValidationError } from './base';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
|
|
4
|
+
interface ChangesetFormFieldsCheckboxArgs extends BaseArgs {
|
|
5
|
+
_groupName?: string;
|
|
6
|
+
_parentOnChange?: (value: unknown, event: Event) => void;
|
|
7
|
+
|
|
8
|
+
onChange?: (value: unknown, event: Event) => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default class ChangesetFormFieldsCheckbox extends Base<ChangesetFormFieldsCheckboxArgs> {
|
|
12
|
+
get fullFieldName(): string {
|
|
13
|
+
return this.args._groupName
|
|
14
|
+
? `${this.args._groupName}.${this.args.fieldName}`
|
|
15
|
+
: this.args.fieldName;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get value(): unknown {
|
|
19
|
+
return this.args.changeset.get(this.fullFieldName);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get errors(): string[] {
|
|
23
|
+
if (typeof this.args.errors !== 'undefined') {
|
|
24
|
+
return this.args.errors;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const fieldErrors = this.args.changeset.errors.filter((error) => {
|
|
28
|
+
return error.key === this.fullFieldName;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return fieldErrors.reduce(
|
|
32
|
+
(errors: string[], error: ValidationError): string[] => {
|
|
33
|
+
return [...errors, ...error.validation];
|
|
34
|
+
},
|
|
35
|
+
[]
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@action async validate(): Promise<void> {
|
|
40
|
+
await this.args.changeset.validate(this.fullFieldName);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@action async handleChange(value: unknown, event: Event): Promise<void> {
|
|
44
|
+
this.args.changeset.set(this.fullFieldName, value);
|
|
45
|
+
|
|
46
|
+
await this.validate();
|
|
47
|
+
|
|
48
|
+
if (typeof this.args._parentOnChange === 'function') {
|
|
49
|
+
this.args._parentOnChange(value, event);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (typeof this.args.onChange === 'function') {
|
|
53
|
+
this.args.onChange(value, event);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<FormInput
|
|
2
|
+
{{on "blur" this.validate}}
|
|
3
|
+
|
|
4
|
+
@value={{this.value}}
|
|
5
|
+
@onInput={{this.handleInput}}
|
|
6
|
+
@errors={{this.errors}}
|
|
7
|
+
|
|
8
|
+
@hasSubmitted={{@hasSubmitted}}
|
|
9
|
+
@type={{@type}}
|
|
10
|
+
@label={{@label}}
|
|
11
|
+
@hint={{@hint}}
|
|
12
|
+
@hasError={{@hasError}}
|
|
13
|
+
@containerClass={{@containerClass}}
|
|
14
|
+
@size={{@size}}
|
|
15
|
+
@onChange={{@onChange}}
|
|
16
|
+
@onFocusIn={{@onFocusIn}}
|
|
17
|
+
@onFocusOut={{@onFocusOut}}
|
|
18
|
+
|
|
19
|
+
...attributes
|
|
20
|
+
>
|
|
21
|
+
{{yield}}
|
|
22
|
+
</FormInput>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Base, { BaseArgs } from './base';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
|
|
4
|
+
interface ChangesetFormFieldsInputArgs extends BaseArgs {
|
|
5
|
+
onInput?: (value: string, event: InputEvent) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default class ChangesetFormFieldsInput extends Base<ChangesetFormFieldsInputArgs> {
|
|
9
|
+
@action handleInput(value: string, event: InputEvent): void {
|
|
10
|
+
this.args.changeset.set(this.args.fieldName, value);
|
|
11
|
+
|
|
12
|
+
if (typeof this.args.onInput === 'function') {
|
|
13
|
+
this.args.onInput(value, event);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<FormRadioGroup
|
|
2
|
+
@onChange={{this.handleChange}}
|
|
3
|
+
@value={{this.value}}
|
|
4
|
+
@errors={{this.errors}}
|
|
5
|
+
|
|
6
|
+
@label={{@label}}
|
|
7
|
+
@hint={{@hint}}
|
|
8
|
+
@hasSubmitted={{@hasSubmitted}}
|
|
9
|
+
@hasError={{@hasError}}
|
|
10
|
+
@containerClass={{@containerClass}}
|
|
11
|
+
@size={{@size}}
|
|
12
|
+
@isInline={{@isInline}}
|
|
13
|
+
|
|
14
|
+
...attributes
|
|
15
|
+
as |Radio|
|
|
16
|
+
>
|
|
17
|
+
{{yield Radio}}
|
|
18
|
+
</FormRadioGroup>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Base, { BaseArgs } from './base';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
|
|
4
|
+
interface Args extends BaseArgs {
|
|
5
|
+
onChange?: (value: unknown, event: Event) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default class ChangesetFormFieldsRadioGroup extends Base<Args> {
|
|
9
|
+
@action
|
|
10
|
+
async handleChange(value: unknown, event: Event): Promise<void> {
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
|
|
13
|
+
this.args.changeset.set(this.args.fieldName, value);
|
|
14
|
+
await this.validate();
|
|
15
|
+
|
|
16
|
+
if (typeof this.args.onChange === 'function') {
|
|
17
|
+
this.args.onChange(value, event);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<FormRadio
|
|
2
|
+
@onChange={{this.handleChange}}
|
|
3
|
+
@checked={{this.value}}
|
|
4
|
+
@hint={{@hint}}
|
|
5
|
+
@value={{@value}}
|
|
6
|
+
@name={{@name}}
|
|
7
|
+
@containerClass={{@containerClass}}
|
|
8
|
+
@size={{@size}}
|
|
9
|
+
...attributes
|
|
10
|
+
{{on "blur" this.validate}}
|
|
11
|
+
>
|
|
12
|
+
{{#if (has-block)}}
|
|
13
|
+
{{yield}}
|
|
14
|
+
{{else}}
|
|
15
|
+
{{@label}}
|
|
16
|
+
{{/if}}
|
|
17
|
+
</FormRadio>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import Base, { BaseArgs } from './base';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
|
|
4
|
+
interface ChangesetFormFieldsRadioArgs extends BaseArgs {
|
|
5
|
+
onChange?: (value: unknown, event: Event) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default class ChangesetFormFieldsRadio extends Base<ChangesetFormFieldsRadioArgs> {
|
|
9
|
+
@action
|
|
10
|
+
async handleChange(value: unknown, event: Event): Promise<void> {
|
|
11
|
+
event.preventDefault();
|
|
12
|
+
|
|
13
|
+
this.args.changeset.set(this.args.fieldName, value);
|
|
14
|
+
await this.validate();
|
|
15
|
+
|
|
16
|
+
if (typeof this.args.onChange === 'function') {
|
|
17
|
+
this.args.onChange(value, event);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<FormSelect
|
|
2
|
+
@selected={{this.value}}
|
|
3
|
+
@onChange={{this.handleChange}}
|
|
4
|
+
@onFocusOut={{this.handleFocusOut}}
|
|
5
|
+
@onClose={{this.handleClose}}
|
|
6
|
+
@errors={{this.errors}}
|
|
7
|
+
@hasSubmitted={{@hasSubmitted}}
|
|
8
|
+
|
|
9
|
+
@isMultiple={{@isMultiple}}
|
|
10
|
+
@label={{@label}}
|
|
11
|
+
@hint={{@hint}}
|
|
12
|
+
@hasError={{@hasError}}
|
|
13
|
+
@containerClass={{@containerClass}}
|
|
14
|
+
@size={{@size}}
|
|
15
|
+
|
|
16
|
+
@onFocusIn={{@onFocusIn}}
|
|
17
|
+
@onFocus={{@onFocus}}
|
|
18
|
+
@onBlur={{@onBlur}}
|
|
19
|
+
@onOpen={{@onOpen}}
|
|
20
|
+
@triggerClass={{@triggerClass}}
|
|
21
|
+
@highlightOnHover={{@highlightOnHover}}
|
|
22
|
+
@placeholderComponent={{@placeholderComponent}}
|
|
23
|
+
@searchMessage={{@searchMessage}}
|
|
24
|
+
@noMatchesMessage={{@noMatchesMessage}}
|
|
25
|
+
@matchTriggerWidth={{@matchTriggerWidth}}
|
|
26
|
+
@options={{@options}}
|
|
27
|
+
@closeOnSelect={{@closeOnSelect}}
|
|
28
|
+
@defaultHighlighted={{@defaultHighlighted}}
|
|
29
|
+
@searchField={{@searchField}}
|
|
30
|
+
@searchEnabled={{@searchEnabled}}
|
|
31
|
+
@tabindex={{@tabindex}}
|
|
32
|
+
@triggerComponent={{@triggerComponent}}
|
|
33
|
+
@matcher={{@matcher}}
|
|
34
|
+
@initiallyOpened={{@initiallyOpened}}
|
|
35
|
+
@typeAheadOptionMatcher={{@typeAheadOptionMatcher}}
|
|
36
|
+
@buildSelection={{@buildSelection}}
|
|
37
|
+
@search={{@search}}
|
|
38
|
+
@onInput={{@onInput}}
|
|
39
|
+
@onKeydown={{@onKeydown}}
|
|
40
|
+
@scrollTo={{@scrollTo}}
|
|
41
|
+
@registerAPI={{@registerAPI}}
|
|
42
|
+
@horizontalPosition={{@horizontalPosition}}
|
|
43
|
+
@destination={{@destination}}
|
|
44
|
+
@preventScroll={{@preventScroll}}
|
|
45
|
+
@renderInPlace={{@renderInPlace}}
|
|
46
|
+
@verticalPosition={{@verticalPosition}}
|
|
47
|
+
@disabled={{@disabled}}
|
|
48
|
+
@calculatePosition={{@calculatePosition}}
|
|
49
|
+
@eventType={{@eventType}}
|
|
50
|
+
@ariaLabel={{@ariaLabel}}
|
|
51
|
+
@required={{@required}}
|
|
52
|
+
@triggerRole={{@triggerRole}}
|
|
53
|
+
@title={{@title}}
|
|
54
|
+
@triggerId={{@triggerId}}
|
|
55
|
+
@allowClear={{@allowClear}}
|
|
56
|
+
@loadingMessage={{@loadingMessage}}
|
|
57
|
+
@selectedItemComponent={{@selectedItemComponent}}
|
|
58
|
+
@dropdownClass={{@dropdownClass}}
|
|
59
|
+
@beforeOptionsComponent={{@beforeOptionsComponent}}
|
|
60
|
+
@placeholder={{@placeholder}}
|
|
61
|
+
@searchPlaceholder={{@searchPlaceholder}}
|
|
62
|
+
@searchMessageComponent={{@searchMessageComponent}}
|
|
63
|
+
@optionsComponent={{@optionsComponent}}
|
|
64
|
+
@extra={{@extra}}
|
|
65
|
+
@groupComponent={{@groupComponent}}
|
|
66
|
+
@afterOptionsComponent={{@afterOptionsComponent}}
|
|
67
|
+
|
|
68
|
+
...attributes
|
|
69
|
+
as |option term|
|
|
70
|
+
>
|
|
71
|
+
{{yield option term}}
|
|
72
|
+
</FormSelect>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Base, { BaseArgs } from './base';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
import { Select } from 'ember-power-select/addon/components/power-select';
|
|
4
|
+
|
|
5
|
+
interface ChangesetFormFieldsSelectArgs extends BaseArgs {
|
|
6
|
+
onChange?: (selection: unknown, select: Select, event?: Event) => void;
|
|
7
|
+
onFocusOut?: (select: Select, event: FocusEvent) => void;
|
|
8
|
+
onClose?: (select: Select, event: Event) => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default class ChangesetFormFieldsSelect extends Base<ChangesetFormFieldsSelectArgs> {
|
|
12
|
+
@action
|
|
13
|
+
async handleChange(
|
|
14
|
+
selection: unknown,
|
|
15
|
+
select: Select,
|
|
16
|
+
event?: Event
|
|
17
|
+
): Promise<void> {
|
|
18
|
+
this.args.changeset.set(this.args.fieldName, selection);
|
|
19
|
+
await this.validate();
|
|
20
|
+
|
|
21
|
+
if (typeof this.args.onChange === 'function') {
|
|
22
|
+
this.args.onChange(selection, select, event);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@action
|
|
27
|
+
async handleFocusOut(select: Select, event: FocusEvent): Promise<void> {
|
|
28
|
+
await this.validate();
|
|
29
|
+
|
|
30
|
+
if (typeof this.args.onFocusOut === 'function') {
|
|
31
|
+
this.args.onFocusOut(select, event);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@action
|
|
36
|
+
async handleClose(select: Select, event: Event): Promise<void> {
|
|
37
|
+
await this.validate();
|
|
38
|
+
|
|
39
|
+
if (typeof this.args.onClose === 'function') {
|
|
40
|
+
this.args.onClose(select, event);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<FormTextarea
|
|
2
|
+
{{on "blur" this.validate}}
|
|
3
|
+
|
|
4
|
+
@value={{this.value}}
|
|
5
|
+
@onInput={{this.handleInput}}
|
|
6
|
+
@errors={{this.errors}}
|
|
7
|
+
|
|
8
|
+
@hasSubmitted={{@hasSubmitted}}
|
|
9
|
+
@type={{@type}}
|
|
10
|
+
@label={{@label}}
|
|
11
|
+
@hint={{@hint}}
|
|
12
|
+
@hasError={{@hasError}}
|
|
13
|
+
@containerClass={{@containerClass}}
|
|
14
|
+
@size={{@size}}
|
|
15
|
+
@onChange={{@onChange}}
|
|
16
|
+
@onFocusIn={{@onFocusIn}}
|
|
17
|
+
@onFocusOut={{@onFocusOut}}
|
|
18
|
+
|
|
19
|
+
...attributes
|
|
20
|
+
>
|
|
21
|
+
{{yield}}
|
|
22
|
+
</FormTextarea>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Base, { BaseArgs } from './base';
|
|
2
|
+
import { action } from '@ember/object';
|
|
3
|
+
|
|
4
|
+
interface ChangesetFormFieldsTextareaArgs extends BaseArgs {
|
|
5
|
+
onInput?: (value: string, event: InputEvent) => void;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default class ChangesetFormFieldsTextarea extends Base<ChangesetFormFieldsTextareaArgs> {
|
|
9
|
+
@action handleInput(value: string, event: InputEvent): void {
|
|
10
|
+
this.args.changeset.set(this.args.fieldName, value);
|
|
11
|
+
|
|
12
|
+
if (typeof this.args.onInput === 'function') {
|
|
13
|
+
this.args.onInput(value, event);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<form
|
|
2
|
+
...attributes
|
|
3
|
+
{{on "submit" (fn this.handleSubmit @changeset)}}
|
|
4
|
+
{{on "reset" (fn this.handleReset @changeset)}}
|
|
5
|
+
>
|
|
6
|
+
<ChangesetForm::Context @changeset={{@changeset}} as |Form|>
|
|
7
|
+
{{yield
|
|
8
|
+
(hash
|
|
9
|
+
Input=(component Form.Input hasSubmitted=this.hasSubmitted)
|
|
10
|
+
Textarea=(component Form.Textarea hasSubmitted=this.hasSubmitted)
|
|
11
|
+
Select=(component Form.Select hasSubmitted=this.hasSubmitted)
|
|
12
|
+
Checkbox=(component Form.Checkbox hasSubmitted=this.hasSubmitted)
|
|
13
|
+
CheckboxGroup=(component
|
|
14
|
+
Form.CheckboxGroup hasSubmitted=this.hasSubmitted
|
|
15
|
+
)
|
|
16
|
+
Radio=(component Form.Radio hasSubmitted=this.hasSubmitted)
|
|
17
|
+
RadioGroup=(component Form.RadioGroup hasSubmitted=this.hasSubmitted)
|
|
18
|
+
)
|
|
19
|
+
@changeset
|
|
20
|
+
(hash hasSubmitted=this.hasSubmitted)
|
|
21
|
+
}}
|
|
22
|
+
</ChangesetForm::Context>
|
|
23
|
+
</form>
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
import { BufferedChangeset } from 'ember-changeset/types';
|
|
4
|
+
import { action } from '@ember/object';
|
|
5
|
+
import { assert } from '@ember/debug';
|
|
6
|
+
|
|
7
|
+
interface ChangesetFormArgs {
|
|
8
|
+
/** Changeset Object */
|
|
9
|
+
changeset: BufferedChangeset;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Run Changeset execute method instead of save
|
|
13
|
+
* @defaultValue false
|
|
14
|
+
* */
|
|
15
|
+
runExecuteInsteadOfSave?: boolean;
|
|
16
|
+
|
|
17
|
+
/** Callback exeuted when from `onsubmit` event is triggered */
|
|
18
|
+
onSubmit?: (data: unknown, event: Event) => void;
|
|
19
|
+
|
|
20
|
+
/** Callback exeuted when from `onreset` event is triggered */
|
|
21
|
+
onReset?: (data: unknown, event: Event) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default class ChangesetForm extends Component<ChangesetFormArgs> {
|
|
25
|
+
@tracked hasSubmitted = false;
|
|
26
|
+
|
|
27
|
+
constructor(owner: unknown, args: ChangesetFormArgs) {
|
|
28
|
+
super(owner, args);
|
|
29
|
+
assert(
|
|
30
|
+
'@changeset must be defined on <ChangesetForm> component',
|
|
31
|
+
this.args.changeset
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@action
|
|
36
|
+
async handleSubmit(
|
|
37
|
+
changeset: BufferedChangeset,
|
|
38
|
+
event: Event
|
|
39
|
+
): Promise<void> {
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
await changeset.validate();
|
|
42
|
+
|
|
43
|
+
this.hasSubmitted = true;
|
|
44
|
+
|
|
45
|
+
if (changeset.isInvalid) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let result;
|
|
50
|
+
if (this.args.runExecuteInsteadOfSave) {
|
|
51
|
+
result = changeset.execute();
|
|
52
|
+
} else {
|
|
53
|
+
result = await changeset.save({});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (typeof this.args.onSubmit === 'function') {
|
|
57
|
+
this.args.onSubmit(result.data, event);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@action
|
|
62
|
+
handleReset(changeset: BufferedChangeset, event: Event): void {
|
|
63
|
+
event.preventDefault();
|
|
64
|
+
this.hasSubmitted = false;
|
|
65
|
+
|
|
66
|
+
const { data } = changeset.rollback();
|
|
67
|
+
if (typeof this.args.onReset === 'function') {
|
|
68
|
+
this.args.onReset(data, event);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@frontile/changeset-form/components/changeset-form/context';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@frontile/changeset-form/components/changeset-form/fields/checkbox-group';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@frontile/changeset-form/components/changeset-form/fields/checkbox';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@frontile/changeset-form/components/changeset-form/fields/input';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from '@frontile/changeset-form/components/changeset-form/fields/radio-group';
|