Currently, I have a Django form that has N rows of 12 columns in the form of text fields in the form of a table. Users can fill out this form with one text box at a time:
[________] [________] [________] [________] [________] [________] [________] [________] [________] [________] [________] [________] [________] [________] [________] [________] [________ ] [________] [________] [________] [________] [________] [________] [________] [________] [________] [________]
Note. Only 9 columns are shown in this table, but the actual form I use is 12.
I would like to add the ability for users to copy a range of cells in Excel and paste into the form, filling in the corresponding cells.
I tried to imitate the syntax for a method that I successfully created that can clear all data fields after clicking the clear button on the form:
$(document).on("click", "#clear_button", function() { $("input[type=text]").val(""); });
The data coming from Excel for a single row is limited to tabs, and this is roughly the way I got it:
$(document).on("paste", "input[type=text]", function(){ var input_id = $(this).attr("id"); var value = $(this).val(); var value_split_array = value.split("\t"); var row_selected = input_id.match(/([-\w]+)_\d+/)[1]; var num = parseInt(input_id.match(/[-\w]+_(\d+)/)[1], 10); for (i=num; i < value_split_array.length-1 || i < 12; i++) { $("[id="+row_selected+"_"+i+"]").val(value_split_array[i-num]); } });
I thought this would work, but unfortunately this did not happen. I wonder if anyone has any suggestions.
source share