File tree Expand file tree Collapse file tree 7 files changed +64
-21
lines changed
templates/components/forms Expand file tree Collapse file tree 7 files changed +64
-21
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ export default Component.extend(FormMixin, {
27
27
attendee . set ( 'firstname' , '' ) ;
28
28
attendee . set ( 'lastname' , '' ) ;
29
29
attendee . set ( 'email' , '' ) ;
30
+ attendee . set ( 'complexFieldValues' , { } ) ;
30
31
} ) ;
31
32
return this . data . attendees ;
32
33
} ) ,
@@ -471,6 +472,17 @@ export default Component.extend(FormMixin, {
471
472
validationRules . fields [ `facebook_required_${ index } ` ] = facebookRequiredValidation ;
472
473
validationRules . fields [ `github_${ index } ` ] = githubValidation ;
473
474
validationRules . fields [ `github_required_${ index } ` ] = githubRequiredValidation ;
475
+ this . allFields . attendee . filter ( field => field . isComplex && field . isRequired ) . forEach ( field => {
476
+ validationRules . fields [ `${ field . fieldIdentifier } _required_${ index } ` ] = {
477
+ rules : [
478
+ {
479
+ type : 'empty' ,
480
+ prompt : this . l10n . t ( 'Please enter ' + field . name )
481
+ }
482
+ ]
483
+ } ;
484
+ } ) ;
485
+
474
486
} ) ;
475
487
return validationRules ;
476
488
} ,
Original file line number Diff line number Diff line change 1
1
import Component from '@ember/component' ;
2
2
import FormMixin from 'open-event-frontend/mixins/form' ;
3
3
4
+ function getIdentifier ( name , fields ) {
5
+ return name . toLowerCase ( ) ;
6
+ }
7
+
4
8
export default Component . extend ( FormMixin , {
5
9
actions : {
6
10
saveDraft ( ) {
@@ -19,6 +23,18 @@ export default Component.extend(FormMixin, {
19
23
this . set ( 'data.event.state' , 'published' ) ;
20
24
this . sendAction ( 'save' , this . data ) ;
21
25
} ) ;
26
+ } ,
27
+ addFormField ( ) {
28
+ this . data . customForms . pushObject ( this . store . createRecord ( 'custom-form' , {
29
+ fieldIdentifier : getIdentifier ( this . data . newFormField . name ) ,
30
+ name : this . data . newFormField . name ,
31
+ form : 'attendee' ,
32
+ type : this . data . newFormField . type ,
33
+ isRequired : false ,
34
+ isIncluded : false ,
35
+ event : this . data . event
36
+ } ) ) ;
37
+ this . set ( 'data.newFormField.name' , '' ) ;
22
38
}
23
39
}
24
40
} ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export default ModelBase.extend({
8
8
fieldIdentifier : attr ( 'string' ) ,
9
9
form : attr ( 'string' ) ,
10
10
type : attr ( 'string' , { defaultValue : 'text' } ) ,
11
+ name : attr ( 'string' ) ,
11
12
isRequired : attr ( 'boolean' , { defaultValue : false } ) ,
12
13
isIncluded : attr ( 'boolean' , { defaultValue : false } ) ,
13
14
isFixed : attr ( 'boolean' , { defaultValue : false } ) ,
@@ -83,18 +84,8 @@ export default ModelBase.extend({
83
84
ageGroup : 'Age Group'
84
85
} ,
85
86
86
- name : computed ( 'fieldIdentifier' , 'form' , function ( ) {
87
- let name = this . fieldIdentifier ;
88
- if ( ! this . isComplex ) {
89
- if ( this . form === 'session' ) {
90
- name = this . get ( `session.${ name } ` ) ;
91
- } else if ( this . form === 'speaker' ) {
92
- name = this . get ( `speaker.${ name } ` ) ;
93
- } else {
94
- name = this . get ( `attendee.${ name } ` ) ;
95
- }
96
- }
97
- return name ;
87
+ identifierPath : computed ( 'isComplex' , function ( ) {
88
+ return ! this . isComplex ? this . fieldIdentifier : 'complexFieldValues.' + this . fieldIdentifier ;
98
89
} ) ,
99
90
100
91
isLongText : computed ( 'type' , function ( ) {
Original file line number Diff line number Diff line change @@ -15,14 +15,19 @@ export default class AttendeeRoute extends Route.extend(CustomFormMixin) {
15
15
val : 'attendee'
16
16
} ] ;
17
17
18
+ const event = this . modelFor ( 'events.view' ) ;
18
19
const data = {
19
- event : this . modelFor ( 'events.view' )
20
+ event,
21
+ customForms : await event . query ( 'customForms' , {
22
+ filter : filterOptions ,
23
+ sort : 'id' ,
24
+ 'page[size]' : 50
25
+ } ) ,
26
+ newFormField : {
27
+ name : '' ,
28
+ type : 'text'
29
+ }
20
30
} ;
21
- data . customForms = await data . event . query ( 'customForms' , {
22
- filter : filterOptions ,
23
- sort : 'id' ,
24
- 'page[size]' : 50
25
- } ) ;
26
31
27
32
return data ;
28
33
}
Original file line number Diff line number Diff line change @@ -34,7 +34,14 @@ export default class NewRoute extends Route {
34
34
event : eventDetails ,
35
35
tickets,
36
36
form : await eventDetails . query ( 'customForms' , {
37
- 'page[size]' : 50 ,
37
+ filter : [
38
+ {
39
+ name : 'form' ,
40
+ op : 'eq' ,
41
+ val : 'attendee'
42
+ }
43
+ ] ,
44
+ 'page[size]' : 0 ,
38
45
sort : 'id'
39
46
} )
40
47
} ;
Original file line number Diff line number Diff line change 73
73
{{ #if (and this.sameAsBuyer (eq index 0 ) (or (eq field.fieldIdentifier ' firstname' ) (eq field.fieldIdentifier ' lastname' ) (eq field.fieldIdentifier ' email' )))}}
74
74
<Input
75
75
@type ={{ field.type }}
76
- @value ={{ mut (get holder field.fieldIdentifier )}}
76
+ @value ={{ mut (get holder field.identifierPath )}}
77
77
@name ={{ if field.isRequired (concat field.fieldIdentifier " _required_" index ) (concat field.fieldIdentifier " _" index )}}
78
78
@readonly =" " />
79
79
{{ else }}
80
80
<Input
81
81
@type ={{ field.type }}
82
- @value ={{ mut (get holder field.fieldIdentifier )}}
82
+ @value ={{ mut (get holder field.identifierPath )}}
83
83
@name ={{ if field.isRequired (concat field.fieldIdentifier " _required_" index ) (concat field.fieldIdentifier " _" index )}} />
84
84
{{ /if }}
85
85
{{ /if }}
Original file line number Diff line number Diff line change 92
92
</div >
93
93
</div >
94
94
{{ /if }}
95
+ <Input id =" firstname" @type =" text" @value ={{ this.data.newFormField.name }} />
96
+ <UiDropdown @class =" label" @selected ={{ this.data.newFormField.type }} @onChange ={{ action (mut this.data.newFormField.type )}} >
97
+ <div class =" default text" >
98
+ {{ this.data.newFormField.type }}
99
+ </div >
100
+ <i class =" dropdown icon" ></i >
101
+ <div class =" menu" >
102
+ <div class =" item" data-value =" http" >text</div >
103
+ <div class =" item" data-value =" https" >number</div >
104
+ </div >
105
+ </UiDropdown >
106
+ <button class =" ui button" {{ action ' addFormField' }} >Add</button >
95
107
<div class =" spacer-50" ></div >
96
108
<div class =" {{ if this.device.isMobile ' mini four' ' right floated large' }} ui fields buttons" >
97
109
<button class =" ui three field left labeled icon button {{ if this.isLoading ' disabled' }} " type =" button" {{ action ' move' ' backwards' }} >
You can’t perform that action at this time.
0 commit comments