2

I'm trying to dynamically to create a form in pug.

form(method='POST' action=postRoute)
                        each component in step.components
                            .row
                                if (component.pug == 'name')
                                    input(type="text", name="title")
                                    include component/name
                                else if (component.pug == 'description')
                                    include component/description
                                else if (component.pug == 'thumbnail')
                                    include component/imageLoader
                                else if (component.pug == 'tag_field')
                                    include component/addTags
                                else if (component.pug == 'tag_equipment')
                                    include component/addEquipmentTags
                                else if (component.pug == 'plans')
                                    .add-plans-background-area
                                        .row
                                            a(href='#')
                                                .add-plan(onclick='addNewPlan()') +
                                        - for (var i = 0; i < 3; ++i)
                                            .row.plan-preview-in-create(onclick='previewPlan()')
                                                .col-md-1
                                                    img(src='https://www.healthline.com/hlcmsresource/images/bodybuilding-meal-plan-1296x728-feature.jpg').plan-thumbnail
                                                .col-md-10
                                                    .plan-name= 'Package name ' + i

                                                .col-md-1
                                                    .plan-exit
                                                        a(href='#' onclick='removePlanFromPackage()')
                                                            i.material-icons.menu-icon= 'close'


                                else
                                    p= component.pug

                        .row.buttons-group
                            - if (index == 0)
                                .col-md-2
                                    button(type="button" onclick=`nextInStepSectionDidClick('${stepIds}', '${index}')`).next-button-base.next-button-enable NEXT
                            - else if (index == (config.length - 1))
                                .col-md-2
                                    button(type="button" onclick=`backInStepSectionDidClick('${stepIds}', '${index}')`).back-button-base BACK
                                .col-md-2
                                    button.next-button-base.next-button(type='submit') SAVE
                            - else
                                .col-md-2
                                    button(type="button" onclick=`backInStepSectionDidClick('${stepIds}', '${index}')`).back-button-base BACK
                                .col-md-2
                                    button(type="button" onclick=`nextInStepSectionDidClick('${stepIds}', '${index}')`).next-button-base.next-button-enable NEXT

As you can see I have a for each and from a configuration file, I'm creating the form dynamically. This will help me in the project since I have many similar views.

Anyway, when I submit the form I can't extract the data, but when I add one input above the if statement I'm able to extract it.

// Get submited data
router.post('/', function (req, res) {
    console.log(req.body);
    res.send('Post page');
})

Any thoughts how to solve this?

DaAmidza
  • 336
  • 2
  • 7
  • 25
  • Please edit your question and provide details and an example of "when I add one input above the if statement I'm able to extract it." – Graham May 08 '19 at 07:02

0 Answers0