Question

In my Objective-C Cocoa app I have a model named Group with several properties (like name, description, creation date etc.), which has KVO-compliant validation methods for each of it's properties.

There is an NSTableView bound to NSArrayController and showing a list of groups which the user can modify.

Now, if I check the "Validates immediately" checkbox within the "Group Name" column's Value binding, the validation works as expected and if user enters invalid group name, an alert box is shown.

What I want to do is to suppress alert box and just mark the corresponding table row with red color.

Is it possible somehow to change the way Cocoa notifies users about validation errors?

Was it helpful?

Solution

As per Key-Value Coding Programming Guide :

The validation infrastructure provides a class the opportunity to accept a value, provide an alternate value, or deny the new value for a property and give a reason for the error.

That's it. Other behaviour is not supported out of the box.

It shouldn't be too hard to implement custom behaviour, however:

You could e.g. provide an alternate value in case the validation fails and set some custom flag somewhere in your model that would in turn allow your table view to indicate the failed validation accordingly. Next time the value is validated and passes the validation you could then reset the flag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top