From 2815d462be3fd706ea76523fefa251ece8548d0a Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Fri, 16 Sep 2011 20:51:45 +0100 Subject: [PATCH] Refs #1360. Test for CPTokenField tokenField:shouldAddObjects:atIndex:. --- Tests/Manual/CPTokenFieldTest/AppController.j | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Tests/Manual/CPTokenFieldTest/AppController.j b/Tests/Manual/CPTokenFieldTest/AppController.j index e1ed23d11..ea8fc7038 100644 --- a/Tests/Manual/CPTokenFieldTest/AppController.j +++ b/Tests/Manual/CPTokenFieldTest/AppController.j @@ -15,6 +15,7 @@ var STATES = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorad CPTokenField tokenFieldD; CPArray allPersons; + CPButton manipulateTokenInsertionButton; } - (void)applicationDidFinishLaunching:(CPNotification)aNotification @@ -53,6 +54,10 @@ var STATES = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorad [contentView addSubview:tokenFieldB]; + manipulateTokenInsertionButton = [CPCheckBox checkBoxWithTitle:"Token transformations"]; + [manipulateTokenInsertionButton setFrame:CGRectMake(525, 110, 200, 50)]; + [contentView addSubview:manipulateTokenInsertionButton]; + var tokenFieldC = [[CPTokenField alloc] initWithFrame:CGRectMake(15, 170, 500, 30)], labelC = [[CPTextField alloc] initWithFrame:CGRectMake(15, 150, 500, 24)]; @@ -148,6 +153,25 @@ var STATES = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorad CPLog.info("tokenFieldAction: " + sender); } +- (CPArray)tokenField:tokenField shouldAddObjects:tokens atIndex:index +{ + CPLog.info("tokenField: " + tokenField + " shouldAddObjects: " + tokens + " atIndex: " + index); + + // Texas -> Utah, Michigan -> Michigan & Arkansas, Washington -> nil + + if ([manipulateTokenInsertionButton intValue]) + { + if (tokens[0] == "Texas") + return ["Utah"]; + else if (tokens[0] == "Michigan") + return ["Michigan", "Arkansas"]; + else if (tokens[0] == "Washington") + return []; + } + + return tokens; +} + @end // A sample of a custom Object