Skip to content

Commit

Permalink
Merge pull request ResearchKit#83 from dephillipsmichael/bug/FPHS-290
Browse files Browse the repository at this point in the history
bug/FPHS-290
  • Loading branch information
Erin-Mounts committed Feb 27, 2016
2 parents e9d623a + db64847 commit e62b6ad
Show file tree
Hide file tree
Showing 2 changed files with 33 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
31 changes: 29 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,39 @@ - (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)
{
NSString* otherStr = NSLocalizedStringWithDefaultValue(@"Other", @"APCAppCore", APCBundle(), @"Other", @"Spinner Option");
// Smart capitalization will lowercase the "Other" option if all the other answers are lowercase
if (sAPCSmartSurveyEnableOtherAutoCapitalization &&
[self allLowercaseOptions:localConstraints])
{
otherStr = [otherStr lowercaseString];
}
[options addObject:otherStr];
}
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 e62b6ad

Please sign in to comment.