Skip to main content
Participating Frequently
January 7, 2024
Question

Change property edittext

  • January 7, 2024
  • 2 replies
  • 310 views

Why doesn't this work?

 

function createWindow() {
dialog = new Window("dialog", "My Dialog");

widthLink = dialog.add("edittext", undefined, "Initial Text", { readonly: true });
var editLinkButton = dialog.add("button", undefined, "Edit");

editLinkButton.onClick = function() {
widthLink.readonly = false;


};

dialog.show();
}

createWindow();

This topic has been closed for replies.

2 replies

CarlosCanto
Community Expert
Community Expert
January 7, 2024

to add to what femkeblanco said, those properties are called "creation properties" which are only set at creation time. Once the dialog is rendered you can read the properties but you can not change them.

femkeblanco
Legend
January 7, 2024

"readonly" is a property of an object called "properties".  So the expression to access it would be "widthLink.properties.readonly".  Having said that, it seems to operate exclusively as an argument to add().  It can be overwritten in the next line and it won't do anything.  Off the top of my head, there are two workarounds. 

 

1.  Remove and recreate the edittext, although this produces an unexpected location, even when the bounds are set. 

function createWindow() {
    var dialog = new Window("dialog", "My Dialog");
    var widthLink = dialog.add("edittext", [20, 20, 100, 40], "Initial Text", 
        { readonly: true });
    var editLinkButton = dialog.add("button", undefined, "Edit");
    editLinkButton.onClick = function() {
        dialog.remove(widthLink);
        widthLink = dialog.add("edittext", [20, 20, 100, 40], "Initial Text", 
            { readonly: false });
    };
    dialog.show();
}

createWindow();

 

2.  Recreate the window.

function createWindow(readonly) {
    var dialog = new Window("dialog", "My Dialog");
    widthLink = dialog.add("edittext", undefined, "Initial Text", 
        { readonly: readonly });
    var editLinkButton = dialog.add("button", undefined, "Edit");
    editLinkButton.onClick = function() {
        dialog.close();
        createWindow(false);
    };
    dialog.show();
}

createWindow(true);