Hey, is there a way that a button can be showed/visified/enabled when there are only numbers in the NSTextField ?
-And I know this question isn’t in the title but is it also possible to only show/etc. the button when there are a certain amount of characters (numbers is the above is possible) are typed ? for example, only make a button clickable when there are 14 numbers typed ?
Really thanks in advance.
I think this is my last question.
Hi,
probably there are smarter methods, but I use this in one of my projects.
Connect the text field to the on changed handler
on changed theObject
set textValue to string value of theObject
set textValue to check_integer(textValue)
if textValue contains "´" or textValue contains "`" or textValue contains "^" or textValue contains "~" then set textValue to ""
set string value of theObject to textValue
set enabled of button "button" of window "window" to (length of textValue > 13)
end changed
property ciphers : "0123456789"
on check_integer(v)
tell v
try
if last character is not in ciphers then
if length is 1 then return ""
return text 1 thru -2
else
return (it as integer) as text
end if
on error
return ""
end try
end tell
end check_integer
It works (almost) thanks…
the only problem is, when I type 123456789 -OK but once I type my 10th number, the text box displays “1,23456789E+9” and when I then type another number (making it the 14th characater in total of the box), then the button displays so everything is fine except that I get the E+X thing and the comma when typing the 10th number.
sorry I used the handler with a maximum length of 5 characters
But it’s no problem, this slightly changed handler should work
on check_integer(v)
tell v
try
if last character is not in ciphers then
if length is 1 then return ""
return text 1 thru -2
else
it as integer
return it
end if
on error
return ""
end try
end tell
end check_integer
Oh, that did the trick. I also changed (length of textValue > 13) to (length of textValue = 14).
You’ve been a really BIG help for me, thanks Stefan! If my application once gets developed further till it’s ready to release, then I’ll certainly will give you a copy of it.