Using Sketchup HTML:Dialog I am trying to fill in some input tags from a csv file.
I don't get an error, the code does not seem to get past reader.onload = function(event)
Has anybody had the same issue and found a solution?
dialog = UI::HtmlDialog.new(
{
:dialog_title => "csv",
:scrollable => true,
:resizable => true,
:width => 500,
:height => 600,
:left => 200,
:top => 200,
:min_width => 150,
:min_height => 150,
:max_width =>100,
:max_height => 50,
:style => UI::HtmlDialog::STYLE_DIALOG
})
html = "
<!DOCTYPE html>
<html>
<head>
<title>Dave Loves You</title>
<style>
label {
display: block;
font: 1rem 'Fira Sans', sans-serif;
}
input,
label {
margin: 0.4rem 0;
}
</style>
</head>
<h1>Insert Box Info</h1>
<script>
function mssgme(){
document.getElementById('f_name').value = 'I have changed!';
}
function sendDataToSketchUp() {
var nm = document.getElementById('nam');
var user_input1 = document.getElementById('id1');
var user_input2 = document.getElementById('id2');
var user_input3 = document.getElementById('id3');
sketchup.getUserInput(nm.value, user_input1.value, user_input2.value, user_input3.value)
}
</script>
<script>
function get_Info(){
var csvFile = document.getElementById('f_csv');
console.log(csvFile.value);
document.getElementById('f_name').value = csvFile.value;
var fileList = csvFile.files[0];
console.log('line 58');
var reader = new FileReader();
console.log('line 60');
reader.onload = function(event) {
var content = event.target.result;
console.log('line 63');
var rows = content.split('/n');
var ids = rows[0].split(','); // Split first row to get IDs
var values = rows[1].split(','); // Split second row to get values
for (let i = 0; i < ids.length; i++) {
var element = document.getElementById(ids[i].trim());
if (element) {
element.value = values[i].trim();
alert(values[i]);
}
}
alert('success');
};
}
</script>
<body>
<h1>Open CSV and fill input boxes</h1>
<label for='f_name'>First Name:</label>
<input type='text' id='f_name' name='f_name' value='' />
<label for='l_name'>Last Name:</label>
<input type='text' id='l_name' name='l_name' value='' />
<label for='age'>Age:</label>
<input type='number' id='age' name='age' value='' />
<button onclick='get_Info()'> we </button>
<input type='file' id='f_csv' onchange='get_Info()' accept='.csv'>
</div>
</body>
</html>
"
dialog.set_html(html)
dialog.show
