Skip to content

Commit

Permalink
Allow the user to override autocomplete by hitting return on the keyb…
Browse files Browse the repository at this point in the history
…oard
  • Loading branch information
bartvandendriessche authored and escoz committed Aug 16, 2013
1 parent e3cf732 commit cd38f0f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions quickdialog/QAutoEntryTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@implementation QAutoEntryTableViewCell {
NSString *_lastFullStringWithAutocompletion;
QAutoEntryElement *_autoEntryElement;
BOOL _autoCompleteEnabled;
}

@synthesize autoCompleteField = _autoCompleteField;
Expand Down Expand Up @@ -105,8 +106,8 @@ - (void)prepareForReuse {
}

-(void)textFieldDidEndEditing:(UITextField *)textField {
_autoCompleteField.text = self.lastFullStringWithAutocompletion;
if (! [_entryElement.textValue isEqualToString:_autoCompleteField.text]) {
if (_autoCompleteEnabled && ![_entryElement.textValue isEqualToString:self.lastFullStringWithAutocompletion]) {
_autoCompleteField.text = self.lastFullStringWithAutocompletion;
// In an AutoEntryElement, a DidEndEditing event might actually be a
// change to the text value. This is because it is an implicit acceptance
// of the displayed auto-chosen value.
Expand All @@ -116,25 +117,29 @@ -(void)textFieldDidEndEditing:(UITextField *)textField {
}

- (void)textFieldEditingChanged:(UITextField *)textField {
_autoCompleteEnabled = YES;
_entryElement.textValue = _autoCompleteField.text;
[_entryElement handleEditingChanged];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
BOOL previousAutoCompleteEnabledValue = _autoCompleteEnabled;
_autoCompleteEnabled = NO;
BOOL result = [super textFieldShouldReturn:textField];
[textField resignFirstResponder];
_autoCompleteEnabled = previousAutoCompleteEnabledValue;
return result;
}
- (BOOL)becomeFirstResponder {
_autoCompleteEnabled = NO;
[_autoCompleteField becomeFirstResponder];
return YES;
}


#pragma mark - DOAutocompleteTextFieldDelegate
- (NSString *)textField:(DOAutocompleteTextField *)textField completionForPrefix:(NSString *)prefix
{
if (!prefix) {
if (!prefix || !_autoCompleteEnabled) {
return nil;
}

Expand Down

0 comments on commit cd38f0f

Please sign in to comment.