From 82421b6cacb94aa3d9aaea785e8f333d0a0c82aa Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 15 Sep 2010 16:44:36 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20validation=20for=20BIT=20fields=20w?= =?UTF-8?q?hile=20in-cell-editing;=20only=201=20or=200=20are=20allowed=20t?= =?UTF-8?q?o=20type=20in=20=E2=80=A2=20enabled=20max=20length=20and=20BIT?= =?UTF-8?q?=20field=20validation=20for=20CustomQuery?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPCustomQuery.m | 27 +++++++++++++++++++++++---- Source/SPDataCellFormatter.m | 12 ++++-------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index 6818dd7f..2a805da2 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -1480,6 +1480,16 @@ [dataCell setFont:tableFont]; [dataCell setLineBreakMode:NSLineBreakByTruncatingTail]; + [dataCell setFormatter:[[SPDataCellFormatter new] autorelease]]; + + // Set field length limit if field is a varchar to match varchar length + if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"string"] + || [[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"bit"]) { + [[dataCell formatter] setTextLimit:[[columnDefinition objectForKey:@"char_length"] integerValue]]; + } + + // Set field type for validations + [[dataCell formatter] setFieldType:[columnDefinition objectForKey:@"type"]]; [theCol setDataCell:dataCell]; [[theCol headerCell] setStringValue:[columnDefinition objectForKey:@"name"]]; @@ -2249,10 +2259,19 @@ NSArray *editStatus = [self fieldEditStatusForRow:rowIndex andColumn:[aTableColumn identifier]]; isFieldEditable = ([[editStatus objectAtIndex:0] integerValue] == 1) ? YES : NO; - // Set max text length - if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"string"] - && [columnDefinition valueForKey:@"char_length"]) - [fieldEditor setTextMaxLength:[[columnDefinition valueForKey:@"char_length"] integerValue]]; + NSString *fieldType = nil; + NSUInteger *fieldLength = 0; + NSString *fieldEncoding = nil; + // Retrieve the column defintion + fieldType = [columnDefinition objectForKey:@"type"]; + if([columnDefinition objectForKey:@"char_length"]) + fieldLength = [[columnDefinition objectForKey:@"char_length"] integerValue]; + if([columnDefinition objectForKey:@"charset_name"] && ![[columnDefinition objectForKey:@"charset_name"] isEqualToString:@"binary"]) + fieldEncoding = [columnDefinition objectForKey:@"charset_name"]; + + [fieldEditor setTextMaxLength:fieldLength]; + [fieldEditor setFieldType:(fieldType==nil) ? @"" : fieldType]; + [fieldEditor setFieldEncoding:(fieldEncoding==nil) ? @"" : fieldEncoding]; id originalData = [resultData cellDataAtRow:rowIndex column:[[aTableColumn identifier] integerValue]]; if ([originalData isNSNull]) originalData = [prefs objectForKey:SPNullValue]; diff --git a/Source/SPDataCellFormatter.m b/Source/SPDataCellFormatter.m index 9e7944f8..f82bad1e 100644 --- a/Source/SPDataCellFormatter.m +++ b/Source/SPDataCellFormatter.m @@ -94,18 +94,14 @@ // Check for BIT fields whether 1 or 0 are typed if(fieldType && [fieldType length] && [[fieldType uppercaseString] isEqualToString:@"BIT"]) { - if(partialString == nil || ![partialString length]) return YES; + if([partialString rangeOfCharacterFromSet:[[NSCharacterSet characterSetWithCharactersInString:@"01"] invertedSet]].location != NSNotFound) { + [SPTooltip showWithObject:NSLocalizedString(@"For BIT fields only “1” or “0” are allowed.", @"For BIT fields only “1” or “0” are allowed.")]; + return NO; + } - // TODO HansJB return YES; - // if() { - // [SPTooltip showWithObject:NSLocalizedString(@"For BIT fields only “1” or “0” are allowed.", @"For BIT fields only “1” or “0” are allowed.")]; - // return NO; - // } - } - return YES; } -- cgit v1.2.3