Skip to main content
Silly-V
Legend
February 8, 2016
Answered

ScriptUI readonly edittext with justify = "center" ?

  • February 8, 2016
  • 1 reply
  • 3475 views

In the great Peter Kahrel's latest issue of the ScriptUI guide, (the value of which approaches the incalculable ) there are examples of adding an "edittext" input text field with a "readonly" creation property to make sure users can't overwrite the shown text, and there are example of doing the same and making it center-justified. However, there is not an example which shows both at the same time. I want center-justified readonly edittext.
This appears to be at least more of a CC issue, as in CS5 the following works while in CC2015 it does not:

function test(){

  var w = new Window("dialog", "Test");

  var e = w.add("edittext", undefined, "abcde", {readonly : true});

  e.justify = "center";

  e.characters = 10;

  w.show();

};

test();

Adding it as resource string does work in CC2015, but putting "readonly : true" into the curly braces has no desired effect.

function test2(){

  var w = new Window("dialog", "Test");

  var e = w.add('edittext {text: "abcde", characters: 10, justify: "center"}');

  e.characters = 10;

  w.show();

};

test2();

Maybe there's some other interesting way to add the 'readonly' property to the resource string, or to add the 'justify' property to the non-string method so that they will work in CC2015?

This topic has been closed for replies.
Correct answer CarlosCanto

May I add, this whole issue is ridiculous, since it purely arises out of CC scriptUI problem of not dealing with the .justify property, or the .readonly property in a single convention by which the elements are added. A "changing" event to workaround this has its own problem which had to be worked-around. I wonder if they won't just add the option of html display to ScriptUI one day.


Hi Silly-V, yeah it's unfortunate that ScriptUI not only doesn't get updated, but it also breaks little by little with every release.

html support? now that would great!!

in the mean time, I got your test2 to work with the resource string

function test2(){

    var w = new Window('dialog', 'Test');

  

    var eResource = "EditText { properties:{multiline:false, readonly:true}, text:'<your message here>', justify:'center' } ";

    var e = w.add(eResource);

    e.characters = 20;

    w.show();

};

test2();

1 reply

Qwertyfly___
Legend
February 8, 2016

you could fake it.

this could be done in a number of ways.

this way seems straight forward, and should work for you.

function test(){

  var w = new Window("dialog", "Test");

  w.orientation = 'stack';

  var h = w.add('edittext', undefined, '', {readonly : true});

  h.characters = 10;

  var e = w.add ('edittext', undefined, 'abcde', {readonly : true, borderless:true});

  w.show();

};

test();

I know this is just a test, but it would pay to add these stacked elements to a group so you don't mess with the rest off the windows orientation.

check out pg 100-101 of the ScriptUI for dummies, there are Mac/PC differences when it comes to stacking...

I've not played with it much so don't know how much effect it will have

Silly-V
Silly-VAuthor
Legend
February 8, 2016

I tested this idea just now, and it works alright, until the text content is swapped for content of longer length.

Previously when I dealt with this issue, I tried to put a "changing" event listener to restore the text back to a string stored in some custom property. The problem was, it didn't work too well, since the event wouldn't refresh the text! It still did the job, but when the focus was taken off. Now, I tried to de-focus the input with .active = false and .active = true, but that's not good enough, it took the .enabled property to budge it. Here is what I'm thinking:

function test3(){

  function makeCenteredNonEdittext(parent, characters, content){

  var e = parent.add('edittext {text: "' + content + '", characters: ' + characters + ', justify: "center"}');

  e.storedText = content;

  e.setValue = function(value){

    this.storedText = value;

    this.text = value;

  };

  e.addEventListener('changing', function(){

    this.enabled = false;

    this.text = this.storedText;

    this.enabled = true;

  });

  return e;

  };

  var w = new Window("dialog", "Test");

  var testText_1 = makeCenteredNonEdittext(w, 20, "Abcdefg Hi Jk Lmno");

  var btn = w.add("button", undefined, "Test");

  btn.onClick = function(){

  var newContents = prompt("Enter some Text", testText_1.storedText);

  if(!newContents){

  return;

  }

  testText_1.setValue( newContents );

  };

  w.show();

};

test3();

Silly-V
Silly-VAuthor
Legend
February 8, 2016

May I add, this whole issue is ridiculous, since it purely arises out of CC scriptUI problem of not dealing with the .justify property, or the .readonly property in a single convention by which the elements are added. A "changing" event to workaround this has its own problem which had to be worked-around. I wonder if they won't just add the option of html display to ScriptUI one day.