• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ScriptUI - StaticText to EditText

Participant ,
Apr 09, 2019 Apr 09, 2019

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();

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Apr 09, 2019 Apr 09, 2019

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

...

Votes

Translate

Translate
Advocate ,
Apr 09, 2019 Apr 09, 2019

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Apr 11, 2019 Apr 11, 2019

Copy link to clipboard

Copied

LATEST

Thanks Tomas.

That it passable when the user has finished typing and exited the "edittext",

that "edittext" will revert back to being "static text"?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines