Skip to content

Commit f085f33

Browse files
feature-8785:Implement dropdown with a number in custom forms (#8802)
* feature-8785:Implement dropdown with a number in custom forms * Remove min in custom form input hbs --------- Co-authored-by: Mario Behling <[email protected]>
1 parent c8bc396 commit f085f33

File tree

6 files changed

+61
-3
lines changed

6 files changed

+61
-3
lines changed

app/components/forms/wizard/custom-form-input.hbs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@
66
</span>
77
</div>
88
<div {{did-update this.updated @field}} class="ui action input" style="width: inherit;">
9-
<Input type="text" placeholder={{t "Field Name"}} @value={{this.name}} />
9+
<Input type="text" placeholder={{t "Field Name"}} @value={{this.name}} style="width: 25%"/>
10+
{{#if (eq this.type "number")}}
11+
<div class="ui action input input-attendee-custom-form">
12+
<Input
13+
@type="number"
14+
@name="min_price"
15+
placeholder={{t "Min"}}
16+
@value={{this.min}} />
17+
</div>
18+
<div class="ui action input input-attendee-custom-form">
19+
<Input
20+
@type="number"
21+
@name="max_price"
22+
placeholder={{t "Max"}}
23+
@value={{this.max}} />
24+
</div>
25+
{{/if}}
1026
<UiDropdown class="ui selection dropdown custom-form-dropdown-attendee" @selected={{this.type}} @onChange={{action (mut this.type)}}>
1127
<div class="default text">
1228
{{ this.type }}

app/components/forms/wizard/custom-form-input.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { inject as service } from '@ember/service';
55
import DS from 'ember-data';
66
import { tracked } from '@glimmer/tracking';
77

8-
interface CustomForm { fieldIdentifier: string, name: string, type: string }
8+
interface CustomForm { fieldIdentifier: string, name: string, type: string, min: number, max: number}
99

1010
function getIdentifier(name: string, fields: CustomForm[]): string {
1111
const fieldIdentifiers = new Set(fields.map(field => field.fieldIdentifier));
@@ -22,6 +22,8 @@ interface Args {
2222
customForms: CustomForm[],
2323
form: string,
2424
event: any,
25+
min: number | 0,
26+
max: number | 10,
2527
onSave: (() => void) | null
2628
}
2729

@@ -36,13 +38,23 @@ export default class CustomFormInput extends Component<Args> {
3638
@service
3739
store!: DS.Store;
3840

41+
@tracked
42+
min = 0;
43+
44+
@tracked
45+
max = 10;
46+
3947
@action
4048
updated(): void {
4149
if (this.args.field) {
4250
this.name = this.args.field.name;
4351
this.type = this.args.field.type;
52+
this.min = this.args.field.min;
53+
this.max = this.args.field.max;
4454
} else {
4555
this.name = '';
56+
this.min = 0;
57+
this.max = 10;
4658
}
4759
}
4860

@@ -66,7 +78,9 @@ export default class CustomFormInput extends Component<Args> {
6678
isRequired : false,
6779
isIncluded : false,
6880
isComplex : true,
69-
event : this.args.event
81+
event : this.args.event,
82+
min : this.min,
83+
max : this.max,
7084
});
7185
}
7286

@@ -79,10 +93,14 @@ export default class CustomFormInput extends Component<Args> {
7993
this.args.field.name = this.name;
8094
this.args.field.type = this.type;
8195
this.args.field.fieldIdentifier = this.identifier;
96+
this.args.field.min = this.min;
97+
this.args.field.max = this.max;
8298
} else {
8399
this.args.customForms.pushObject(this.field);
84100
}
85101
this.name = '';
102+
this.min = 0;
103+
this.max = 10;
86104

87105
this.args.onSave && this.args.onSave();
88106
}

app/components/forms/wizard/custom-forms/table.hbs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<th class="center aligned">
2525
{{t 'Type'}}
2626
</th>
27+
{{#if this.editColumn}}
28+
<th class="center aligned">
29+
{{t 'Range'}}
30+
</th>
31+
{{/if}}
2732
<th class="center aligned">
2833
{{t 'Include'}}
2934
</th>
@@ -57,6 +62,11 @@
5762
<td class="border center aligned">
5863
{{t-var field.type}}
5964
</td>
65+
{{#if this.editColumn}}
66+
<td class="border center aligned">
67+
{{if (eq field.type "number") (concat field.min " - " field.max) "-"}}
68+
</td>
69+
{{/if}}
6070
<td class="border center aligned">
6171
<UiCheckbox
6272
@class="slider"

app/models/custom-form.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export default ModelBase.extend({
6969
position : attr('number'),
7070
isComplex : attr('boolean', { defaultValue: false }),
7171
description : attr('string', { defaultValue: 'text' }),
72+
min : attr('number', { defaultValue: 0 }),
73+
max : attr('number', { defaultValue: 10 }),
7274

7375

7476
event : belongsTo('event'),

app/styles/pages/events.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,9 @@
137137
max-height: 128px !important;
138138
}
139139
}
140+
141+
.input-attendee-custom-form {
142+
input {
143+
border-radius: unset !important;
144+
}
145+
}

app/templates/components/forms/orders/order-form.hbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@
110110
@value={{mut (get holder field.identifierPath)}}
111111
@name={{if field.isRequired (concat field.fieldIdentifier "_required_" index) (concat field.fieldIdentifier "_" index)}}
112112
@readonly="" />
113+
{{else if (eq field.type "number")}}
114+
<Input
115+
@type={{field.type}}
116+
@value={{mut (get holder field.identifierPath)}}
117+
@name={{if field.isRequired (concat field.fieldIdentifier "_required_" index) (concat field.fieldIdentifier "_" index)}}
118+
@min={{if field.min field.min null}} @max={{if field.max field.max null}}/>
113119
{{else}}
114120
<Input
115121
@type={{field.type}}

0 commit comments

Comments
 (0)