Change property edittext
Copy link to clipboard
Copied
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();
Explore related tutorials & articles
Copy link to clipboard
Copied
"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);
Copy link to clipboard
Copied
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.

