Skip to content

Commit 7a62ccc

Browse files
author
Ian Redpath
committed
got saving working
1 parent 53e0a48 commit 7a62ccc

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

public/assignment/views/forms/fields.controller.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ export class FieldsController {
6969
return this.newFieldMap[this.newFieldType]
7070
}
7171
addNewField() {
72-
console.log(this.newFieldType)
73-
console.log(this.getNewField())
7472
this.fieldsService.createFieldForForm(this.formId, this.getNewField())
7573
.subscribe(resp => {
7674
this.fields = resp.json().fields
@@ -90,6 +88,7 @@ export class FieldsController {
9088
if (field.options) {
9189
field.options = this.getOptionsFor(field._id)
9290
}
91+
console.log(field.options)
9392
this.fieldsService.updateField(this.formId, field._id, field)
9493
.subscribe(resp => {
9594
this.fields = resp.json().fields
@@ -100,10 +99,14 @@ export class FieldsController {
10099
getOptionsFor(id) {
101100
const optionString = this.optionsMap[id]
102101
const optionsArray = optionString.split('\n')
103-
return optionsArray.map(opt => {
104-
const labelValuePair = opt.split(":")
105-
return { label: labelValuePair[0], value: labelValuePair[1] }
102+
let retVal = []
103+
optionsArray.forEach(opt => {
104+
if (opt) {
105+
const labelValuePair = opt.split(":")
106+
retVal.push({ label: labelValuePair[0], value: labelValuePair[1] })
107+
}
106108
})
109+
return retVal
107110
}
108111
isTextField(type) {
109112
return type === 'TEXT' || type === 'TEXTAREA'

server/models/form.model.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ export default class FormModel {
5858

5959
getFieldForForm(formId: string, fieldId: string) {
6060
const fields = this.getFieldsForForm(formId)
61-
return _.find(fields, field => { return field._id === fieldId })
61+
return _.find(fields, field => { return field._id.toString() === fieldId.toString() })
6262
}
6363

6464
deleteFieldForForm(formId: string, fieldId: string) {
6565
const form = this.findById(formId)
6666
const fields: Array<any> = form.fields
67-
_.remove(fields, field => { return field._id === fieldId })
67+
_.remove(fields, field => { return field._id.toString() === fieldId.toString() })
6868
return fields
6969
}
7070

@@ -76,13 +76,15 @@ export default class FormModel {
7676
}
7777

7878
updateFieldForForm(formId: string, fieldId: string, field) {
79+
console.log(field)
7980
const form = this.findById(formId)
8081
const fields: Array<any> = form.fields
81-
fields.forEach(f => {
82-
if (field._id === fieldId) {
83-
f = field
82+
form.fields = fields.map(f => {
83+
if (f._id.toString() === fieldId) {
84+
return field
8485
}
86+
return f
8587
})
86-
return fields
88+
return form.fields
8789
}
8890
}

server/services/field.service.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default function FieldEndpoints(app, formModel: FormModel) {
2727
res.status(200).send({ fields: updatedFields })
2828
})
2929

30-
app.put('/api/assignment/form/:formId/field/:fieldid', (req, res) => {
30+
app.put('/api/assignment/form/:formId/field/:fieldId', (req, res) => {
3131
const { formId, fieldId } = req.params
3232
const field = req.body.field
3333
const updatedFields = formModel.updateFieldForForm(formId, fieldId, field)

0 commit comments

Comments
 (0)