Copy link to clipboard
Copied
Hello,
Who can I build StaticText That when I click on it it becomes to EditText?
I tried it but it did not work:
var w = new Window ("dialog");
var e = w.add ("statictext", undefined, "hello");
e.onClick = function (){
e = w.add ("edittext", undefined, "hello");
};
w.show();
Well, that will not work the way you are trying to do.
Your best bet is to create a group element with orientation = 'stack' and place both statictext and edittext in this group. This will make them show on top of each other. So hide edittext element with edittext.visible = false. Now that all looks fine.
However, statictext does not have onClick method, so you'll have to create an event listener: statictext.addEventListener('mousedown', function() {}) that hides statictext element and shows editt
...Copy link to clipboard
Copied
Well, that will not work the way you are trying to do.
Your best bet is to create a group element with orientation = 'stack' and place both statictext and edittext in this group. This will make them show on top of each other. So hide edittext element with edittext.visible = false. Now that all looks fine.
However, statictext does not have onClick method, so you'll have to create an event listener: statictext.addEventListener('mousedown', function() {}) that hides statictext element and shows edittext element. Then refresh the UI for changes to make an effect.
Here's a working snippet
(function (thisObj) {
buildUI(thisObj);
function buildUI(thisObj) {
var win = (thisObj instanceof Panel) ? thisObj : new Window("palette", "script", undefined, {
resizeable: true
});
var group = win.add('group');
group.orientation = 'stack';
group.alignChildren = ['fill', 'top'];
var stText = group.add('statictext', undefined, 'this is static text');
stText.addEventListener('mousedown', function(){
this.visible = false;
etText.visible = true;
resizeUI();
});
var etText = group.add('edittext', undefined, 'this is edit text');
etText.visible = false;
win.onResizing = win.onResize = function () {
this.layout.resize();
};
if (win instanceof Window) {
win.center();
win.show();
} else {
resizeUI();
}
function resizeUI() {
win.layout.layout(true);
win.layout.resize();
}
}
})(this);
Copy link to clipboard
Copied
Thanks Tomas.
That it passable when the user has finished typing and exited the "edittext",
that "edittext" will revert back to being "static text"?