Combobox Focus Issue

All,
I have an app where user can store a car name and its related features and specs. The car names are shown in a combo box. All the data about a car is stored in a plist file. A handler called textfieldDidEndEditing_ is connected to the combo box. Inside this handler I have a statement that calls a function that resets the form fields. The issue is that currently when user enters a new car name in the combo box , and then fills up other form fields, the information gets reset.The problem is that when user enters a new car name in the combo box, and transfers focus to input controls like checkboxes, drop downs and segment controls, the cursor still remains inside the combobox.
When I shift the focus on a textfield, the cursor moves to it and the textfieldDidEndEditing_ handler gets called, reseting the form fields. Is there a way I can avoid this?

Here is the piece of code:

    
    property aCarName : missing value -- Combobox
-- Other form properties...
on textfieldDidEndEditing_(sender)
        try
            set tagNumber to sender's tag() as string 
            if tagNumber is equal to "150" then --combobox tag number
                set currentCarSelection to (aCarName's stringValue) as string --get current selection    
                set doesexist to aCarName's indexOfItemWithObjectValue_(currentCarSelection) -- see if the car exists 
                if doesexist is not equal to (current application's NSNotFound) then
                    my CarForm(currentCarSelection) --if the car exists, update the fields in the UI
                else
                    my reset_form(false)
                end if 
            end if
        end try    
    end textfieldDidEndEditing_

on reset_form(clear_combobox)
        --clear_combobox is flag that determines if the combobox should be cleared.
        if clear_combobox then
            aCarName's setObjectValue_("") 
        end if
--- code to reset all form fields ...

end reset_form

I’m not sure I quite understand your problem, but there are few things you could try. You could use the delegate method, comboBoxSelectionDidChange: to fill in the forms when a user selects a car, but use the textFieldDidEndEditing method for when a user enters a new car, thus separating those two situations into two different methods. You could also try setting the combo box to “End Editing on Enter Only” (or whatever it’s called in IB, I’m not in front of my computer now), so moving the cursor out of the box won’t invoke the handler.

Ric

I’m not sure if I understand, but you could try adding this to textfieldDidEndEditing_:

tell sender's |window|() to makeFirstResponder_(sender's |window|())

You may have to wrap it in performSelector:withObject:afterDelay: .

@Shane/Ric:

Here are the steps to make it clear. I hope they make sense:

Step 1: User enters a new car name in the combo box(auto-complete is enabled).
Step 2: User makes selection in a drop down/ ticks a checkbox/ selects values in a segmented control.
All this while, the cursor is still in the combobox.
Step 3: User then focuses on a textfield to enter a value. The cursor now moves to the textfield. The app thinks that user has stopped editing the combo box and fires the handler textfieldDidEndEditing_ and resets all the form fields.

It sounds like your code to reset the combo box is in the wrong place. You can’t put it in the field’s textfieldDidEndEditing_ handler and not expect it to be call when editing of the text field ends…