Detect which edittext is activated

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
rodrigoaben
Posts: 1
Joined: September 10th, 2020, 10:37 am

I’m using Peter Kahrel’s guide to dinamically create an UI and I want to fill the selected edittext with a keyboard entry. Since all edittexts are created on the fly, how do I check which one is selected? My function works fine on the first one but not on the next field.

Code: Select all

var win = new Window ("dialog");
var maingroup = win.add ("panel {orientation: 'column'}");
add_row (maingroup);
var show_btn = win.add ("button", undefined, "Save presets");
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.statictext = group.add ("statictext", undefined, "Left-click  +");
group.edit = group.add ("edittext", ["", "", 200, 20], "Click here and press any key");
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;
    group.edit.onActivate = function(){
    win.addEventListener ("keydown", function (kd) {pressed (kd)});
    function pressed (k) {
    if(k.keyName === "Enter"){
    group.edit.text = "Enter";
            }
        }
    }
win.layout.layout (true);
}
function add_btn () {
add_row (maingroup);
}
function minus_btn () {
maingroup.remove (this.parent);
win.layout.layout (true);
}
Post Reply