Skip to content

Commit 315050f

Browse files
snitin315iamareebjamal
authored andcommitted
feat: add ageGroup Field in attendee form (#3803)
1 parent aa10c3f commit 315050f

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

app/components/forms/orders/order-form.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
validGithubProfileUrlPattern
1212
} from 'open-event-frontend/utils/validators';
1313
import { genders } from 'open-event-frontend/utils/dictionary/genders';
14+
import { ageGroups } from 'open-event-frontend/utils/dictionary/age-groups';
1415

1516
export default Component.extend(FormMixin, {
1617
router: service(),
@@ -100,6 +101,15 @@ export default Component.extend(FormMixin, {
100101
]
101102
};
102103

104+
let ageGroupValidation = {
105+
rules: [
106+
{
107+
type : 'empty',
108+
prompt : this.l10n.t('Please select your age group')
109+
}
110+
]
111+
};
112+
103113
let addressValidation = {
104114
rules: [
105115
{
@@ -435,6 +445,7 @@ export default Component.extend(FormMixin, {
435445
validationRules.fields[`lastname_required_${index}`] = lastNameValidation;
436446
validationRules.fields[`email_required_${index}`] = emailValidation;
437447
validationRules.fields[`gender_required_${ index}`] = genderValidation;
448+
validationRules.fields[`ageGroup_required_${ index}`] = ageGroupValidation;
438449
validationRules.fields[`address_required_${ index}`] = addressValidation;
439450
validationRules.fields[`city_required_${ index}`] = cityValidation;
440451
validationRules.fields[`state_required_${ index}`] = stateValidation;
@@ -466,7 +477,8 @@ export default Component.extend(FormMixin, {
466477
return groupBy(this.fields.toArray(), field => field.get('form'));
467478
}),
468479

469-
genders: orderBy(genders, 'name'),
480+
genders : orderBy(genders, 'name'),
481+
ageGroups : orderBy(ageGroups, 'age'),
470482

471483
actions: {
472484
submit(data) {

app/mixins/custom-form.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ export default Mixin.create(MutableArray, {
291291
isIncluded : false,
292292
event : parent
293293
}),
294+
this.store.createRecord('custom-form', {
295+
fieldIdentifier : 'ageGroup',
296+
form : 'attendee',
297+
type : 'select',
298+
isRequired : false,
299+
isIncluded : false,
300+
event : parent
301+
}),
294302
this.store.createRecord('custom-form', {
295303
fieldIdentifier : 'address',
296304
form : 'attendee',

app/models/attendee.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export default ModelBase.extend({
3232
facebook : attr('string'),
3333
github : attr('string'),
3434
gender : attr('string'),
35+
ageGroup : attr('string'),
3536
birthDate : attr('moment'),
3637
complexFieldValues : attr(),
3738

app/models/custom-form.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ export default ModelBase.extend({
7979
twitter : 'Twitter',
8080
facebook : 'Facebook',
8181
github : 'GitHub',
82-
gender : 'Gender'
82+
gender : 'Gender',
83+
ageGroup : 'Age Group'
8384
},
8485

8586
name: computed('fieldIdentifier', 'form', function() {

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@
9090
{{/each}}
9191
</div>
9292
{{/ui-dropdown}}
93+
{{else if (eq field.fieldIdentifier 'ageGroup')}}
94+
{{#ui-dropdown class='search selection' value=(mut (get holder field.fieldIdentifier)) onChange=(action (mut holder.ageGroup)) as |execute mapper|}}
95+
{{input type='hidden' name=(if field.isRequired (concat field.fieldIdentifier '_required_' index) (concat field.fieldIdentifier '_' index))}}
96+
<i class="dropdown icon"></i>
97+
<div class="default text">{{t 'Select your age group'}}</div>
98+
<div class="menu">
99+
{{#each ageGroups as |ageGroup|}}
100+
<div class="item" data-value="{{map-value mapper ageGroup.age}}">
101+
{{ageGroup.age}}
102+
</div>
103+
{{/each}}
104+
</div>
105+
{{/ui-dropdown}}
93106
{{/if}}
94107
</div>
95108
{{/if}}

app/utils/dictionary/age-groups.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const ageGroups = [
2+
{
3+
age: '19 or less'
4+
},
5+
{
6+
age: '20 to 29'
7+
},
8+
{
9+
age: '30 to 39'
10+
},
11+
{
12+
age: '40 to 49'
13+
},
14+
{
15+
age: '50 or above'
16+
}
17+
];

0 commit comments

Comments
 (0)