dynamically adding a field and submitting new field to server

dynamically adding a field and submitting new field to server

wblakencwblakenc Posts: 77Questions: 17Answers: 1

Hello,
I am working on a contact management solution and need to have the ability to dynamically add input fields to capture contact information for multiple people. At the time the form is initialized I can only assume there will be at least one contact, but I do not know if there are 2 or 10 more contacts my users would like to enter. From a UI perspective, when the user starts typing in contact information, I am able to use editor add() to add a new field for the second contact, third etc. However when the data is submitted to the server, the dynamically created fields do not show in the JSON string.

I assume it is because the newly created fields have been added to the UI but editor object is unaware of them.

Any thoughts or ideas? I would assume the editor add() function would add it to the UI and the data object.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin
    Answer ✓

    add() added fields should indeed be included included in the submitted data.

    On this page if you open a browser console and enter:

    editor.add({name:'test', label: 'Test:'});
    

    it will add a form element dynamically to the form. Click submit and it submits it:

    action:create
    data[0][first_name]:1
    data[0][last_name]:2
    data[0][position]:3
    data[0][office]:4
    data[0][extn]:54
    data[0][start_date]:2017-12-09
    data[0][salary]:6
    data[0][test]:7
    

    Can you link to a test page showing the issue please?

    Allan

  • wblakencwblakenc Posts: 77Questions: 17Answers: 1

    Thanks for the quick answer Allan. I set up a testing server that I am happy to share, but in doing so I realized very quickly that I was looking at the response from the server after adding the record and not what was submitted. It looks like the add() function is working as expected.

    In any case, it forced me to set up a QA environment which was desperately needed. Thanks again for the great support and software.

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    No problem - good to hear that helped :).

    Allan

This discussion has been closed.