Re: NSTextField and bindings
Re: NSTextField and bindings
- Subject: Re: NSTextField and bindings
- From: mmalcolm crawford <email@hidden>
- Date: Tue, 4 May 2004 12:35:24 -0700
On May 4, 2004, at 11:48 AM, Steve Sims wrote:
On 4 May 2004, at 12:38, Fritz Anderson wrote:
The Key-Value Validation documentation says, "Note: Key-value coding
does not perform validation automatically, it is your applications
responsibility to invoke the validation methods. Also, an
implementation of -set<Key>: for a property should never call the
validation methods."
This would seem to make KVV useless for your (or many) purposes,
I'm not sure how that follows? How to validate is a "business"
decision; when to validate is an application control issue...
The goal of Key-Value Validation is to provide a uniform architecture
for validation.
but the value binding on the text field has a "Validate Immediately"
switch that does in fact automatically call KVV on the value.
Hmmm... Interesting. This would indeed seem to be the way to do
things, so I just wrote a validator as follows:
- (BOOL)validateText:(id *)ioValue error:(NSError **)outError
{
if ((*ioValue == nil) || ([*ioValue length]==0)) {
*ioValue = text;
}
return YES;
}
...plus of course I got rid of the check in my setText for zero length
strings.
However this just seems to give me the same results. When I put
breakpoints in my validator and setter methods I see that they are
both getting called when one would expect them to, and they seem to do
their job OK. My model ends up with valid data, which is good,
however my UI does not reflect the model, which is not so good.
This is a known bug (reported here at some point). Nevertheless, you
are discouraged from changing values in validation methods.
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.