macek/jquery-serialize-object

Does not work with dynamically added inputs.

bgallagh3r opened this issue · 4 comments

I tried using this script on a form in which I add a number of hidden input fields via jQuery when an event is added via FullCalendar. However when I serialize the form none of the hidden inputs are converted.
This worked with a different script I was using but it did not convert inputs into arrays like name='dates[]

Any chance you can paste more code with this?

jQuery.serializeArray does pick up hidden inputs

    $(document).ready(function() {

        var calendar = $('#calendar');

        calendar.fullCalendar({
            // This method is envoked when a user clicks on a day in the calendar, a prompt opens asking for a string for the event name.
            select: function(start, end) {

                    // Bunch of validation and stuff here...

                    var selectedDay = $.fullCalendar.moment(start).format();
                    $('<input>').attr({
                            type: 'hidden',
                            name: 'dates['+selectedDay+']',
                            value:title // title is set from event data in the validation bit above
                    })
                    .addClass('date-input')
                    .appendTo(form);

                    }
                    calendar.fullCalendar('unselect');
                }

            }
        });

        var form = $('#calendar-form');

        form.on('submit', function(event) {
            event.preventDefault();
            console.log(form.serializeObject());          
        });

    });

Not really sure how to help you much further without tinkering with those specific dependencies.

I did put together a plnkr for your here

hidden inputs demo

You can browse the source code to see that hidden inputs work as intended.

Marking this invalid and closing it. If you find more evidence to support that hidden inputs are buggy with this plugin, please let me know.