I try to implement a continuous verification of a text field: by typing a integer ID, the user sees if the ID is not yet attributed (red message near the text field and “OK” button disabled). This:
implement the delegate notification controlTextDidChange_(aNotification) in your controller class and connect the delegate of the text field to the controller class in Interface Builder
controlTextDidChange_ leads to four pages of Objective-C in the documentation, my eyes are blushing… It sounds simple (and certainly is) but these concepts are new to me…
“implement the delegate notification” = create a handler in the code?
“in your controller class” = do I have to create a new class, with interface/implementation files?
“the delegate of the text field” is a delegation by right-clicking the objects in IB?
Thanks for your patience ” of course I should have tried something less ambitious, like “if theNumber is in myList then display alert”, but I learn more when it’s difficult…
But… I loose the effect of my Number formatter (on the same field) - the user can type anything, including alphabetics, negative or huge numbers… the formatter appears greyed out. Is there only one possible delegate for notifications?
is definitely not so handy as an old eventRecord… what can I make with this? For instance, how recognize which character was entered ? I must test the entire contents of the text field (as string)?
Get the integer value of the text field (the object of the notification)
If the string is not a valid integer, the result will be 0.
In this case get the string value of the text field, cut the last character and write the string back into the text field.
For the user it seems that the key was not accepted
Finally solved so (the error stay displayed so the user knows what’s wrong) :
on controlTextDidChange_(aNotification)
set acceptable to (gProposedCardID is not missing value) and (gProposedCardID as integer > 1) and (gProposedCardID as integer < 32767) and (not gNavigatorArray's containsObject_(gProposedCardID))
gProposedCardIDWarning's setHidden_(acceptable)
gCreateWindowOKButton's setEnabled_(acceptable)
end controlTextDidChange_