disabling text field with radio button

I’m working on an app that has 2 radio buttons in a matrix, and then 2 text fields for user input

I want to establish that if user chooses button 1 of matrix, then input can be entered into both text fields,
but if user chooses button 2 of matrix, then the second text field, where input is not needed, becomes disabled

It already works that the app will do different things based on the button selected, but I cannot figure how to disable the text field
I tried editable, selectable, enabled… i need help!

thanks for any help in advance

Hi,

I am not sure if the problem is with your referencing or a simple lack of appropriate property to target.

I checked the property of text field and the only thing I could see there that might be most relevant to your need is the “editable” property which is boolean. You, of course, can control this in the IB but you cannot dynamically change it unless you script it. In your case, you want the property to change based on user’s input.

Can you try again using "set editable of text field “What not” of window “myWindow” to false? This is of course just a guide. You still have to find the right reference to your text field. Set it to false when the conditions that you set have been met.

Invariably, it’s always a matter of properly targeting the object whose property you want to manipulate…in this case the text field that you don’t want users to have editing access to.

Good luck.

archseed :slight_smile:

Provided the following:

the window is called “Main”
the matrix is called “theChoices”
and the text fields are called “Text1” and Text2"

then


on clicked theObject
if current row of theObject is 1 then --> current column if the buttons are side by side
tell window "Main"
set the enabled of text field "Text1" to true
set the enabled of text field "Text2" to true
end tell
-- do other stuff here
else
tell window "Main"
set the enabled of text field "Text1" to true
set the enabled of text field "Text2" to false
end tell
-- do other stuff here
end
end
end clicked

NOTE: if text field “Text1” should always be usable, then the first “set the enabled…” lines aren’t needed.

DISCLAIMER: I created this example off the top of my head, so to speak, but it SHOULD work.

Hope this helps,
Brad Bumgarner, CTA

Brad

i tried your code in a clean test app, and it worked just as I want it to

but now I’m having trouble introducing it into my files… and I’m struggling…
I’m posting my code in hopes that you might have some insight, as I’m sure that due to my inexperience, I’m overlooking something

here’s my app code:

on clicked theObject
	if name of theObject = "Reset" then
		tell window "Folder Generator"
			set contents of text field "fcbName" to ""
			set contents of text field "clientCode" to ""
		end tell
	else if name of theObject = "Generate" then
		set whichServer to current row of matrix "ServerName" of window "Folder Generator"
		if whichServer is equal to 1 then
			
			--PrePress Server
			set destination_ to (choose folder with prompt "Choose a destination for the job folder.") as string
			set fcbFolderName to contents of text field "fcbName" of window "Folder Generator"
			set prefix_ to text -5 thru end of fcbFolderName & "_"
			set clientFolderCode to contents of text field "clientCode" of window "Folder Generator"
			set holdingfolder_names to prefix_ & "Holding/{Old,CompArt,Transmissions}"
			set replace_strings to ¬
				{" ", "  ", "-", "_", "__", "~", "`", ":", ";", "!", "@", "â„¢", "'", "®", "#", "$", "?", "<", ">", "%", "^", "&", ¬
					"*", "(", ")", "=", "+", "{", "}", "[", "]", "|", "\\", "/", "'", ",", "\""}
			set astid to AppleScript's text item delimiters
			repeat with this_replace_string in replace_strings
				set fcbFolderName to my FixName(fcbFolderName, (contents of this_replace_string))
				set clientFolderCode to my FixName(clientFolderCode, (contents of this_replace_string))
			end repeat
			set AppleScript's text item delimiters to astid
			set fcbFolderPOSIX to POSIX path of (destination_ & fcbFolderName) & "/"
			do shell script ("mkdir -p " & fcbFolderPOSIX & clientFolderCode & "/" & holdingfolder_names)
			tell application "Finder" to update folder destination_
			
			
		else if whichServer is equal to 2 then
			--AD Server
			set destination_ to (choose folder with prompt "Choose a destination for the job folder.") as string
			set fcbFolderName to contents of text field "fcbName" of window "Folder Generator"
			set prefix_ to text -5 thru end of fcbFolderName & "_"
			set subfolder_names to prefix_ & "{Old_QXD,ILL_EPS,PSD,Resources,EPS_TIF}"
			set transmission_names to prefix_ & "Transmissions/{In,Out}"
			set replace_strings to ¬
				{" ", "  ", "-", "_", "__", "~", "`", ":", ";", "!", "@", "â„¢", "'", "®", "#", "$", "?", "<", ">", "%", "^", "&", ¬
					"*", "(", ")", "=", "+", "{", "}", "[", "]", "|", "\\", "/", "'", ",", "\""}
			set astid to AppleScript's text item delimiters
			repeat with this_replace_string in replace_strings
				set fcbFolderName to my FixName(fcbFolderName, (contents of this_replace_string))
			end repeat
			set AppleScript's text item delimiters to astid
			set fcbFolderPOSIX to POSIX path of (destination_ & fcbFolderName) & "/"
			do shell script ("mkdir -p " & fcbFolderPOSIX & subfolder_names)
			do shell script ("mkdir -p " & fcbFolderPOSIX & transmission_names)
			tell application "Finder" to update folder destination_
			
		end if
	end if
end clicked

on FixName(currentName, fixString)
	set AppleScript's text item delimiters to fixString
	set listName to every text item of currentName
	set AppleScript's text item delimiters to "_"
	return (listName as string)
end FixName

Bace, if you don’t mind your app requiring OS X v10.3+, then you can use Bindings to do this.

Read this first, if needed: Bindings Your Preferences in AppleScript Studio (OS X v10.3+)

In Interface Builder, select your radio button matrix. Then, in the Inspector, choose Bindings. Choose “selectedIndex” and enter a name in the “Model Key Path” field. Now, select the second text field, but choose “enabled” in the Inspector. After that, enter the same name (as the matrix) in the “Model Key Path” field, and then set the Value Transformer to NSNegateBoolean.

Bruce

your answer worked like a charm, and it opened a whole new path for me-this solution has nothing to do with the actual applescript for the app, but now I need to go learn about “bindings”

your post was so descriptive that I just applied it without reading the articles about bindings, and my app executed as I intended

thanks for all the help

Hi Bruce,

I agree with bace - your suggestion is great!

I did try to follow the tutorial and fiddled around with changing the text color and sizes per hands-on example. And, without any glue code it really shows a way to empower users to do certain things according to their prefs.

Now, my question is: Can this be done with changing the background color of windows? I tried to bind the window for that purpose but I don’t get any option that says I can change the background color. Do you think it’s possible to manipulate this by binding? If so, could you kindly show how?

TIA for any input.

Ciao.

archseed :slight_smile:

You can only use Binding to control what is listed. If you want to control something else, you’ll have to code it yourself.

Base,

Did Bruce get you taken care of? I’ve been buried this week and haven’t even had a chance to read my important email, let alone keep up with the goings on here. I haven’t had a chance to look at the code you posted. If your questions have been answered, great. If not, let me know and (hopefully) I’ll take a look and see what I can do.

Brad Bumgarner, CTA