Dynamically created inputs then getting data from inputs with flask Dynamically created inputs then getting data from inputs with flask flask flask

Dynamically created inputs then getting data from inputs with flask


I noticed that if you want to have all dynamically created inputs with the same name that they must be a different name from the first input field that is not dynamically created. So, I named the first input s0 and the rest of the dynamically created inputs s1. I can then call request.form.get() on s0 and can call request.form.getlist() on s1. I can then append s0 to s1 and I have the list that I wanted, which is full of all the input data. However, it does not work if you let the dynamically created inputs have the same name as the first non dynamically created input.


I donĀ“t know much about flask, but with this code, you can get the array of objects and insert them one by one with your server logic.

https://jsfiddle.net/8gdun4j0/

PS: used jquery

  arrayObject=[];$("#subButon").on("click",function(){for(var index=0;index<count+1;index++){arrayObject.push({stock:$("#stock"+index).val(),weight:$("#weight"+index).val()})}console.log(arrayObject);alert("objetos guardados")})