Set text field visible

Hi, I have a script which sets several text fields visible property to false on launch (to false), then attempt to set their visible properties back to true if they certain criteria is met. This does not appear to be working for me… any suggestions? Thanks,

ex.


on launched theObject

set visible of text field "lbl_wait" of window "main" to false

end launched


on clicked theObject

set visible of text field "lbl_wait" of window "main" to true

end clicked

Hello,

I do not see anything wrong with your code, although I would check if the name you applied to the text field in IB is still there. There is some cases when the field gets emptied for some reason.

And are you sure that the text field is directly in the window’s content area? Not in a tab view or a box for example? You know you have to specify those too, otherwise it wont work, maybe even get an error message.

And I would strongly suggest creating a routine to call upon when needed to switch visibility of elements, something like this:

on toggleVisibility_textField1_textField2_button1(textField1State, textField2State, button1State)
tell window "main"
set visible of text field "textField1" to textField1State
set visible of text field "textField2" to textField2State
set visible of button "button1" to button1State
end
end toggleVisibility_textField1_textField2_button1

This way you can call upon it from anywhere in your app like this:

on launched theObject
my toggleVisibility_textField1_textField2_button1(false, false, false)
end launched
on clicked theObject
my toggleVisibility_textField1_textField2_button1(true, true, true)
end clicked

This way if the path to the object changes, you only have one spot to change it, or if you only want one of the three elements to disappear/appear…

Makes sense?

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Leonsimard:

Thanks for the info, the text field is indeed directly in the main window. I did check the contents of the text field and the text does appear to still exist; I did notice something very strange, when I added the lines:


-- Existing line to set back to visible
set visible of text field "lbl_wait" of window "main"

-- New lines to test contents of
set lblContents to contents of text field "lbl_wait" of window "main"
display dialog lblContents

The text field is displayed, while the dialog box is open? Is there a refresh command I need to perform after setting the visible property?

Regards,

Hi,

Well, to tell you the truth, I have never seen this behavior. Just to check, are you sure that you did not forget the boolean in this line?

-- Existing line to set back to visible
set visible of text field "lbl_wait" of window "main" to false/true

You should also coerce the a variable in cases like this one to either string or text. This is good programming behavior:

set lblContents to contents of text field "lbl_wait" of window "main" as string
display dialog lblContents

What is the visibility state of the text field in interface builder? is the hidden box checked? Trying to pinpoint the problem by testing…

Model: MacBookPro2,2
Browser: Safari 531.9
Operating System: Mac OS X (10.6)