@@ -589,7 +589,6 @@ - (UITableViewCell*)tableView:(UITableView *)tableView newCellForSpecifier:(IASK
589589 }
590590 else if ([identifier hasPrefix: kIASKPSTextFieldSpecifier ]) {
591591 cell = [[IASKPSTextFieldSpecifierViewCell alloc ] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: identifier];
592- [((IASKPSTextFieldSpecifierViewCell*)cell).textField addTarget: self action: @selector (textChanged: ) forControlEvents: UIControlEventEditingChanged];
593592 }
594593 else if ([identifier hasPrefix: kIASKTextViewSpecifier ]) {
595594 cell = [[IASKTextViewCell alloc ] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: identifier];
@@ -1181,17 +1180,32 @@ - (void)textFieldDidBeginEditing:(UITextField *)textField {
11811180 self.currentFirstResponder = textField;
11821181}
11831182
1184- - (void )textChanged : (IASKTextField*)textField {
1183+ - (BOOL )textField : (IASKTextField*)textField shouldChangeCharactersInRange : (NSRange )range replacementString : (NSString *)replacementString {
1184+ NSString *newText = [textField.text stringByReplacingCharactersInRange: range withString: replacementString];
11851185 // Wait with setting the property until editing ends for the addSpecifier of list groups or if a validation delegate is implemented
1186- if ((!textField.specifier .isAddSpecifier && ![self .delegate respondsToSelector: @selector (settingsViewController:validateSpecifier:textField:previousValue:replacement: )]) ||
1186+ IASKValidationResult result = IASKValidationResultOk;
1187+ if ((!textField.specifier .isAddSpecifier ) ||
11871188 (self.listParentViewController && [self .delegate respondsToSelector: @selector (settingsViewController:childPaneIsValidForSpecifier:contentDictionary: )]))
11881189 {
1189- [self .settingsStore setObject: textField.text forSpecifier: textField.specifier];
1190- NSDictionary *userInfo = textField.specifier .key && textField.text ? @{(id )textField.specifier .key : (NSString *)textField.text } : nil ;
1191- [NSNotificationCenter .defaultCenter postNotificationName: kIASKAppSettingChanged
1192- object: self
1193- userInfo: userInfo];
1194- }
1190+ BOOL storeToSettings = YES ;
1191+ if (!textField.specifier .isAddSpecifier && [self .delegate respondsToSelector: @selector (settingsViewController:validateSpecifier:textField:previousValue:replacement: )]) {
1192+ result = [self .delegate settingsViewController: self validateSpecifier: textField.specifier textField: textField previousValue: textField.text replacement: &newText];
1193+ if (result == IASKValidationResultOkWithReplacement) {
1194+ storeToSettings = NO ;
1195+ textField.text = newText;
1196+ } else if (result != IASKValidationResultOk) {
1197+ storeToSettings = NO ;
1198+ }
1199+ }
1200+ if (storeToSettings) {
1201+ [self .settingsStore setObject: newText forSpecifier: textField.specifier];
1202+ NSDictionary *userInfo = textField.specifier .key && newText ? @{(id )textField.specifier .key : newText} : nil ;
1203+ [NSNotificationCenter .defaultCenter postNotificationName: kIASKAppSettingChanged
1204+ object: self
1205+ userInfo: userInfo];
1206+ }
1207+ }
1208+ return result != IASKValidationResultOkWithReplacement;
11951209}
11961210
11971211- (BOOL )textFieldShouldReturn : (UITextField *)textField {
@@ -1216,7 +1230,7 @@ - (void)textFieldDidEndEditing:(IASKTextField *)textField {
12161230 void (^restoreText)(void ) = ^{
12171231 if (![textField.text isEqualToString: replacement]) {
12181232 textField.text = replacement;
1219- [self textChanged : textField];
1233+ [self textField : textField shouldChangeCharactersInRange: NSMakeRange ( 0 , 0 ) replacementString: @" " ];
12201234 }
12211235 };
12221236
0 commit comments