Adding extra editable text fields to a dialogue box but they except text until I add another field
I'm trying to create a dialogue box to collect data for a graph. I need to be able to add extra data fields depending on how many graph lines are needed. The script I have so far allows me to add or subtract data fields but when I add a field the next field will not allow text to be added to it unless I then add another field after it. I have found a hack by adding an empty dummy group along with the text field I want to add which does work but it seems like a very poor way of going about things. Can someone please help?
var win = new Window ("dialog");
var maingroup = win.add ("panel {orientation: 'column'}");
add_row (maingroup);
//add_DummyGroup (maingroup)
var show_btn = win.add ("button", undefined, "show");
show_btn.onClick = function () {
var txt = " ";
for (var n = 0; n < maingroup.children.length; n++) {
txt += maingroup.children[n].edit.text + "\n";
}
alert ("Rows: \n" + txt);
}
win.show ();
function add_row (maingroup) {
var group = maingroup.add ("group");
// group.edit = group.add ("edittext", [" ", " ", 200, 20], maingroup.children.length);
group.edit = group.add ("edittext", [0, 0, 70, 150], "Dummy Text", {multiline: true, scrolling: true});
group.plus = group.add ("button", undefined, "+");
group.plus.onClick = add_btn;
group.minus = group.add ("button", undefined, "-");
group.minus.onClick = minus_btn;
group.index = maingroup.children.length - 1;
win.layout.layout (true);
}
function add_DummyGroup (maingroup) {
var group2 = maingroup.add ("group");
win.layout.layout (true);
}
function add_btn () {
add_row (maingroup);
add_DummyGroup (maingroup)
}
function minus_btn () {
maingroup.remove (this.parent);
win.layout.layout (true);
}