Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate for return key when not completing token #92

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ Similar to ```UITableView```, ```VENTokenField``` provides two protocols: ```<VE
### VENTokenFieldDelegate
This protocol notifies you when things happen in the token field that you might want to know about.

* ```tokenField:didEnterText:``` is called when a user hits the return key on the input field.
* ```tokenField:didEnterText:``` is called when a user hits the return key on the input field, completing a token.
* ```tokenField:didDeleteTokenAtIndex:``` is called when a user deletes a token at a particular index.
* ```tokenField:didChangeText:``` is called when a user changes the text in the input field.
* ```tokenFieldDidBeginEditing:``` is called when the input field becomes first responder.
* ```tokenFieldDidReturn:``` is called when the user hits the return key on the input field with no partial text entered.

### VENTokenFieldDataSource
This protocol allows you to provide info about what you want to present in the token field.
Expand Down
1 change: 1 addition & 0 deletions VENTokenField/VENTokenField.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)tokenField:(VENTokenField *)tokenField didChangeText:(nullable NSString *)text;
- (void)tokenFieldDidBeginEditing:(VENTokenField *)tokenField;
- (void)tokenField:(VENTokenField *)tokenField didChangeContentHeight:(CGFloat)height;
- (void)tokenFieldDidReturn:(VENTokenField *)tokenField;
@end

@protocol VENTokenFieldDataSource <NSObject>
Expand Down
8 changes: 6 additions & 2 deletions VENTokenField/VENTokenField.m
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,14 @@ - (NSString *)collapsedText

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if ([self.delegate respondsToSelector:@selector(tokenField:didEnterText:)]) {
if ([textField.text length]) {
if ([textField.text length]) {
if ([self.delegate respondsToSelector:@selector(tokenField:didEnterText:)]) {
[self.delegate tokenField:self didEnterText:textField.text];
}
} else {
if ([self.delegate respondsToSelector:@selector(tokenFieldDidReturn:)]) {
[self.delegate tokenFieldDidReturn:self];
}
}

return NO;
Expand Down