Skip to content

Commit

Permalink
Added auto capitalization for Other option feature that is defaulted …
Browse files Browse the repository at this point in the history
…to OFF
  • Loading branch information
dephillipsmichael committed Feb 27, 2016
1 parent cc3540c commit c9df50f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@

-(instancetype)initWithIdentifier: (NSString*) identifier survey:(SBBSurvey *)survey;

/*
* @param if YES, will check if all other survey answers are lowercase, and make "other" option lowercase as well, if NO, "Other" will always be capitalized
*/
+ (void) setAPCSmartSurveyAutoCapitalization:(BOOL)autoCapitalization;

@end
33 changes: 31 additions & 2 deletions APCAppCore/APCAppCore/DataSubstrate/Model/APCSmartSurveyTask.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
NSString *const kUiHintKey = @"uihint";
NSString *const kSliderValue = @"slider";

static BOOL sAPCSmartSurveyEnableOtherAutoCapitalization = NO;

@class APCDummyObject;
static APCDummyObject * _dummyObject;
Expand Down Expand Up @@ -571,13 +572,41 @@ - (ORKAnswerFormat*) rkChoiceAnswerFormat:(NSDictionary *)objectDictionary
ORKTextChoice * choice = [ORKTextChoice choiceWithText:option.label detailText:detailText value:option.value exclusive:!localConstraints.allowMultipleValue];
[options addObject: choice];
}];
if (localConstraints.allowOtherValue) {
[options addObject:NSLocalizedStringWithDefaultValue(@"Other", @"APCAppCore", APCBundle(), @"Other", @"Spinner Option")];
if (localConstraints.allowOtherValue)
{
// Smart capitalization will lowercase the "Other" option if all the other answers are lowercase
if (sAPCSmartSurveyEnableOtherAutoCapitalization &&
[self allLowercaseOptions:localConstraints])
{
[options addObject:NSLocalizedStringWithDefaultValue(@"other", @"APCAppCore", APCBundle(), @"other", @"Spinner Option")];
}
else
{
[options addObject:NSLocalizedStringWithDefaultValue(@"Other", @"APCAppCore", APCBundle(), @"Other", @"Spinner Option")];
}
}
retAnswer = [ORKAnswerFormat choiceAnswerFormatWithStyle:localConstraints.allowMultipleValue ? ORKChoiceAnswerStyleMultipleChoice : ORKChoiceAnswerStyleSingleChoice textChoices:options];
return retAnswer;
}

+ (void) setAPCSmartSurveyAutoCapitalization:(BOOL)autoCapitalization
{
sAPCSmartSurveyEnableOtherAutoCapitalization = autoCapitalization;
}

- (BOOL) allLowercaseOptions:(SBBMultiValueConstraints*)options
{
for(SBBSurveyQuestionOption* option in options.enumeration)
{
if (option.label != nil &&
![option.label isEqualToString:[option.label lowercaseString]])
{
return NO;
}
}
return YES;
}

- (ORKAnswerFormat *)rkNumericAnswerFormat:(NSDictionary *)objectDictionary
{
SBBSurveyConstraints * constraints = objectDictionary[kConstraintsKey];
Expand Down

0 comments on commit c9df50f

Please sign in to comment.