I’ve got a small data entry app, with a GUI composed of a window, an inset border, an NSdatepicker date field, a couple of buttons (“Quit” and “Enter”), and a number of text fields of various kinds of data.
What I’d like to do is to have the enter (button or key) trigger processing of the input data, clear the processed fields and reset the cursor position to the first field – and I have that all working fine… almost.
The one thing that I cannot get to happen is to have pressing the enter key trigger the code that sets the first responder to the field I specify. If I click the enter button it works perfectly, but if I press the return key (which is specified as a key equivalent for the enter button via the IB Inspector panel), the focus remains with the last field that was previously occupied by data. Everything else works fine.
Here’s some snippets of the code:
on positionCursor(theWindow, theField)
set first responder of theWindow to text field theField of theWindow
end positionCursor
on clicked theObject
(*Add your script here.*)
set objName to the name of theObject as Unicode text
set theWindow to the window of theObject
if objName = "Quit" then -- the "Quit" button
quit
else if objName = "Enter" then -- the "Enter" button
set dataInput to false
processData(theWindow)
if dataInput then
if insertData() then
resetFields(theWindow)
set dataInput to false
end if
end if
set cursorField to "type01"
positionCursor(theWindow, cursorField)
else if objName = "txndate" then
set txnDate to (content of theObject)
-- format date using NSDateFormatter, extract {yyyy,mm,dd} fields
set txnYYYY to year of txnDate as small integer
set txnMM to (month of txnDate as integer) as small integer
set txnDD to day of txnDate as small integer
end if
end clicked
I’m guessing that some field – possibly the last text field with data in it (where the focus was when I pressed Enter), or maybe the highest-numbered object in the GUI is also getting the enter key-press, but as I have no other code that references the positionCursor routine, I have no idea how it is resetting the first responder.
Or more likely, I’m 'way out in left field, and trying to do this in a totally inappropriate manner.
Anything obvious leap out at anyone?