I want to skip a particular input type (responsible for my row ID for editing). However, in the code below, the first console.log(formObject.rowId) returns a value, while after the serializedArray() the second console.log(formObject.rowId) returns an undefined.
function handleFormSubmit(formObject) {
console.log(formObject.rowId)
var formObject = $("#myForm :input[value!='']").serializeArray()
formObject.push({
name: 'myfile',
value: myfile
})
console.log(formObject.rowId)
google.script.run.withSuccessHandler(createTable).processForm(formObject);
setTimeout(function() {$('#myModal').modal('hide');}, 3000);
document.getElementById("message").innerHTML = "<div class='alert alert-warning' role='alert'>Data added/updated successfully.</div>";
document.getElementById("myForm").reset();
}
Heres the HTML Element for the input type that I want to skip:
<input type="text" id="rowId" name="rowId" value="" style="display: none">
2
Answers
serializeArray
ignores fields that don’t have aname
:Notice how only the
name="x"
was included, not the otherinput
.Maybe using the
:not
pseudo selector (or JQuery.not
) is viable?Furthermore: the selector
#myForm :input[value!='']
seems not to work. Using$(":input[value!='']")
does – see snippet.