Skip to main content
Known Participant
December 20, 2022
Answered

To create and interact with user interface elements

  • December 20, 2022
  • 4 replies
  • 1543 views


Greetings to everyone!
When I call a dialog, I need to pass it the value of the text (StaticText). EditText would like the text to be typed from the center (justify: "center").

I wrote the code for such a window in two versions.
in the first case, I cannot assign a value (StaticText).
In the second version, I cannot make the text in the EditText field aligned in the center.

How to make any of the options work?

 

 

var myTxt = 'figny';

// version1
var w = new Window( "dialog { \
    orientation: 'row', \
    st: StaticText {text:myTxt}, \
    pb: Button { text: 'OK' }, \
    et: EditText { characters:15, justify:'center' } \
    }");
w.show(); 

// version2
win = new Window('dialog');
win.orientation = 'row';
win.st = win.add('statictext', undefined, myTxt);
win.bt = win.add('button', undefined, 'ok');
win.et = win.add('edittext');
win.et.characters = 15;
win.et.justify = 'center';
win.show();

 

This topic has been closed for replies.
Correct answer CarlosCanto

these are all the different ways of using the name property

var win = new Window( 'dialog' );
chInk_10 = win.add( 'checkbox {text:"ink_10", visible:false, properties:{name:"ten"}}' );

// access element by finding the element
var check10 = win.findElement("ten"); // this also works with a name like 10
check10.visible = true;

alert("or by chaining its name: \n\nVisible: " + win.ten.visible); // this won't work with a numeric name, variable names should not start with numbers in general

alert("or by targeting the parent's children name: \n\nVisible: " + win.children["ten"].visible); // name:10 will also work here

win.show();

 

4 replies

pixxxelschubser
Braniac
December 30, 2022

 

 

Hi everyone!
I will continue to ask questions in this topic so as not to create a new one …


By @Dmitriy27445167miri

 

Hello @Dmitriy27445167miri 
even though it may seem advantageous to you at the moment - it is not.

 

The forum works best if you create a separate thread for each question, give it a meaningful title - and in the best case get one or even more correct answers to exactly that question. These answers should then also be marked as correct.

 

This way you and all other future questioners can use the forum search and easily find your question and the corresponding correct answers. Collective topics quickly become confusing. Several correct but possibly completely unrelated answers in a single topic that stretches over many pages is unfortunately of no use to anyone.

 

In future, please create a new topic with a meaningful title for new questions. If you don't know it yet, you can easily find all your topics again. Click on your profile picture (top right of each page) and then in the drop-down menu on: "My profile".

 

Have fun in the forum.

Your friendly forum moderator.

😉

Known Participant
December 30, 2022

Yes, I have already understood my mistake. Excuse me as a newcomer to the forum.
I will not do this again!

pixxxelschubser
Braniac
December 30, 2022

That's not a problem at all. We were all newcomers here once.
😉

 

 

Question:
Could @CarlosCanto 's answer help solve your second problem?

Known Participant
December 29, 2022

Hi everyone!
I will continue to ask questions in this topic so as not to create a new one...
How do I access a management object by its unique name defined in its properties?
I would like to use a variable as a name when accessing.
For example, I create a checkbox with the unique name 10.

var win = new Window( 'dialog' );
chInk_10 = win.add( 'checkbox {text:"ink_10", visible:false, properties:{name:10}}' );
CarlosCanto
CarlosCantoCorrect answer
Braniac
December 30, 2022

these are all the different ways of using the name property

var win = new Window( 'dialog' );
chInk_10 = win.add( 'checkbox {text:"ink_10", visible:false, properties:{name:"ten"}}' );

// access element by finding the element
var check10 = win.findElement("ten"); // this also works with a name like 10
check10.visible = true;

alert("or by chaining its name: \n\nVisible: " + win.ten.visible); // this won't work with a numeric name, variable names should not start with numbers in general

alert("or by targeting the parent's children name: \n\nVisible: " + win.children["ten"].visible); // name:10 will also work here

win.show();

 

Known Participant
December 30, 2022

thank you for your time on my problem.
I had to organize a search for checkboxes by name. And I decided this as follows: I added letters to the number in the name.

As I understand, if you use only digits in the name, then the value of the variable converted String() cannot be substituted as an argument in the function findElement()

var win = new Window( 'dialog' );
chInk_1 = win.add( 'checkbox {text:"ink_10", properties:{name:"ch1"}}' );
// many more checkboxes
chInk_10 = win.add( 'checkbox {text:"ink_10", properties:{name:"ch10"}}' );

for (i = 1; i < 2; i++ ) { // loop, as an example of a variable change
var nameCh = 'ch' + String(i);
win.findElement(nameCh).value = true;
}
win.show();
Charu Rajput
Braniac
December 20, 2022

Try following

var myTxt = 'figny';

// version1
var w = new Window("dialog { \
    orientation: 'row', \
    st: StaticText {text:'" + myTxt + "'},\
    pb: Button { text: 'OK' }, \
    et: EditText { characters:15, justify:'center' } \
    }");
w.show();

// version2
win = new Window('dialog');
win.orientation = 'row';
win.st = win.add('statictext', undefined, myTxt);
win.bt = win.add('button', undefined, 'ok');
win.et = win.add('edittext {text: "", characters: 15, justify: "center", active: true}');
win.show();
Best regards
Known Participant
December 20, 2022

Great!!!
I still need to know a lot about script writing rules

Known Participant
December 20, 2022

Fixed the first option. it works

var myTxt = 'figny';


var w = new Window( "dialog { \
    orientation: 'row', \
    des: StaticText { characters:5 }, \
    pb: Button { text: 'OK' }, \
    et: EditText { characters:15, justify:'center' } \
    }");
w.des.text = myTxt;
w.show();