0

So I basically have a modal to add an object, that I want to serialize to JSON Object. To serialize each input will have a name and value of course.

The thing is one of those inputs have a value which is an array (list of ids). This input is actually hidden and I have set it my self.

Following are the steps I followed

  1. Set the hidden input values

    $('input[name="students"]').val(JSON.stringify(idsArray));
    
  2. Serialize the form into object

    action_object = $('.actionForm').serializeObject();
    

    Source for SerialzeObject function Convert form data to JavaScript object with jQuery

  3. Convert to JSON object

    action_JSON = JSON.stringify(action_object);
    
  4. Result is as following

    {"Title":"","students":"[\"2015022\",\"2015027\",\"2015032\"]","ActionType":"3","Description":"yjtkt","Date":"2015-11-17"}
    

Now the object seems ok.

However check for the students array. Is that normal and if not how that can be fixed ?

Community
  • 1
  • 1
Abdelrahman Shoman
  • 2,882
  • 7
  • 36
  • 61

0 Answers0