I am working on dynamic multi step form .
What I am doing :
1. creating input fields using AJAX
2. taking input field info from user
3. serializeArray()
4. SUbmit (POST) : before submit convert input values into desired format ex: input type=date convert into utc format, which is working fine.
I have multi step format , in first step , I have two fields which has Student Number, Id type=list(to create array) then click on next button and then I have second step form which has Name , date , address.
I am converting date on submit using below code
var dateTypeField = $('form').find('input[type="date"]').attr('name');
var dateField = $('form').find('input[type="date"]').val();
var dateFormat = '';
if (dateField) {
dateFormat = moment.utc(dateField).format('YYYY-MM-DDThh:mm:ss.SSSZ');
}
else {
dateFormat = null;
}
which is working fine .
Question : I have two input fields in first step which has type=list , and value in string , I want to convert string into an array while clicking on submit. this is what I am doing
var listTypeField = $('form').find('input[type="list"]').attr('name');
var inputTypeList = $('form').find('input[type="list"]').val();
listTypeField = inputTypeList.split(',');
var listFormat = inputTypeList.split(',');
var formData = $form.serializeArray();
formData.push({ name: dateTypeField, value: dateFormat });
formData.push({ name: listTypeField, value: inputTypeList });
Issue : 1. I have two fields which has type= list , but showing only one field using $('form').find('input[type="list"]').attr('name') 2. spilt is undefined . 3. How to convert string into an array after serializeArray()? formData.push({ name: listTypeField, value: inputTypeList }); not working for me. I want