0

when instead a textField longer the firstResponder, does not send any signal value and the text color is not correct, how can I fix it?

    RAC(self.textField, textColor) = [RACSignal
                                  combineLatest:@[self.textField.rac_textSignal]
                                         reduce:^(NSString *firstName) {
                                              if (firstName.length > 5) {
                                                  return [UIColor blueColor];
                                              }else{
                                                 return [UIColor redColor];
                                              }
                                  }];
iAcisclo
  • 11
  • 1
  • 1
  • I'm not 100% I understand what you're trying to do. Are you saying the text color changes when the text field is no longer the first responder? What does it change to? Have you tried logging what `firstName` is? – joshaber Mar 12 '14 at 15:00
  • I'm trying to validate a text field changing indicating the color of the text, ie if the text is less than 5 characters must be red while the text field is FirstResponder done correctly, but when you stop be FirstResponder, although the text longer than 5 characters will turn red. I appreciate help. – iAcisclo Mar 12 '14 at 19:32

1 Answers1

0

Assuming you mean this to show the validation state of a field you can do it like this. There are tons of other ways but this is the one that I normally use.

- (void)viewDidLoad {
    [super viewDidLoad];

    // =====================================
    // Other Initialisation Code Here
    // =====================================

    RACSignal *validTextFieldSignal =
        [self.textField.rac_textSignal
            map:^id(NSString *text) {
                return @([self isValidTextField:text]);
            }];


     RAC(self.textField, textColor) =
                [validTextFieldSignal
                    map:^id(NSNumber *textFieldValid) {
                        return [textFieldValid boolValue] ? [UIColor blueColor] : [UIColor redColor];
                    }];
end

- (BOOL)isValidTextField:(NSString *)textField {
    return textField.length > 5;
}
Dave Green
  • 151
  • 9