Skip to content

Commit

Permalink
feat: add custom form widget (#3501)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavk96 authored Oct 30, 2019
1 parent ce9872f commit fd96cb5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
10 changes: 10 additions & 0 deletions app/components/forms/wizard/sessions-speakers-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ export default Component.extend(EventWizardMixin, FormMixin, {
return this.get('data.event.microlocations').filterBy('isDeleted', false);
}),

complexCustomForms: computed('data.customForms.@each.isComplex', function() {
return this.data.customForms.filterBy('isComplex', true);
}),

fieldChanged(field) {
if (!field.get('isIncluded')) {
field.set('isRequired', false);
Expand Down Expand Up @@ -174,6 +178,12 @@ export default Component.extend(EventWizardMixin, FormMixin, {
break;
}
},
addCustomField() {
this.data.customForms.addObject(this.store.createRecord('customForm', {
event : this.data.event,
isComplex : true
}));
},
onChange() {
this.onValid(() => {});
}
Expand Down
15 changes: 8 additions & 7 deletions app/models/custom-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ export default ModelBase.extend({

name: computed('fieldIdentifier', 'form', function() {
let name = this.fieldIdentifier;
if (this.form === 'session') {
name = this.get(`session.${name}`);
} else if (this.form === 'speaker') {
name = this.get(`speaker.${name}`);
} else {
name = this.get(`attendee.${name}`);
if (!this.isComplex) {
if (this.form === 'session') {
name = this.get(`session.${name}`);
} else if (this.form === 'speaker') {
name = this.get(`speaker.${name}`);
} else {
name = this.get(`attendee.${name}`);
}
}

return name;
}),

Expand Down
1 change: 0 additions & 1 deletion app/templates/components/forms/session-speaker-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@




<button type="submit" class="ui teal submit button update-changes">
{{t 'Submit'}}
</button>
Expand Down
39 changes: 39 additions & 0 deletions app/templates/components/forms/wizard/sessions-speakers-step.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,45 @@
<div class="spacer-50"></div>
{{/if}}

{{#each complexCustomForms as |form|}}
{{form.isComplex}}
<div class="fields">
<div class="two wide field">
<label>{{t 'Name'}}</label>
{{input type='text' value=form.fieldIdentifier name='name'}}
</div>
<div class = "two wide field">
<label>{{t 'Form'}}</label>
{{input type='text' value=form.form name='form'}}
</div>
<div class = "two wide field">
<label>{{t 'Type'}}</label>
{{input type='text' value=form.type name='type'}}
</div>
<div class="five wide field">
<label class="required">{{t 'Description'}}</label>
{{input type='text' value=form.description name='desciption'}}
</div>
<div class="five wide field">
<label class="required">{{t 'Required'}}</label>
{{ui-checkbox class='slider'
checked=form.isRequired
onChange=(action (mut form.isRequired))
label=(t 'Required')}}
</div>
<div class="five wide field">
<label class="required">{{t 'Included'}}</label>
{{ui-checkbox class='slider'
checked=form.isIncluded
onChange=(action (mut form.isIncluded))
label=(t 'Included')}}
</div>
</div>
{{/each}}

<button type="button" class="ui primary {{if device.isMobile 'small'}} button" {{action 'addCustomField'}}>{{t 'Add another custom field'}}</button>


<div class="ui fields buttons {{if device.isMobile 'mini three' 'right floated large'}}">
<button class="ui three field left labeled icon button {{if isLoading 'disabled'}}" type="button" {{action 'move' 'backwards'}}>
{{t 'Previous'}}
Expand Down

0 comments on commit fd96cb5

Please sign in to comment.