On Dec 30, 2008, at 11:09 AM, Ronnie B wrote:

Hi All and Happy New Year ,

I am trying to do something not usual with the modal sheet. I have a field and a submit button on a sheet, and I want to implement some validation
behavior.

I'd say this is completely usual.


Two things I am trying to achieve are:
1. If the field's data fails my validation, I want to have the colored red
border around the field
2. I would like not to have the sheet dismissed until validation passes.

So, the sheet is displayed, user enters an invalid data, OK pressed, sheet remains open, red border appears around the field. User enters a valid
data, OK pressed, sheet is dismissed.

In my UI I turn both the label and the text in the text field red, show a (previously hidden) text label under the field that describes why the data is invalid, and place the cursor in the field with the error.

So, if I have Password and Confirm Password fields and the user does not enter the confirm password correctly I do:

        BOOL foundError = NO;
        if ([password isEqualToString:confirmPassword]) {
                [confirmPasswordErrorLabel setHidden:YES];
                [confirmPasswordField setTextColor:[NSColor blackColor]];
                [confirmPasswordLabel setTextColor:[NSColor blackColor]];
        } else {
                foundError = YES;
                [confirmPasswordErrorLabel setHidden:NO];
                [confirmPasswordField setTextColor:[NSColor redColor]];
                [confirmPasswordLabel setTextColor:[NSColor redColor]];
                [[self window] makeFirstResponder:confirmPasswordField];
        }

If there are multiple fields that need this sort of validation then I start from the bottom one and test each one going up the sheet. This way the cursor is in the topmost field with an error when done.

Put your version of this code in the IBAction method called by the OK button, if foundError is NO then close the sheet normally and go on your merry way, if not then do nothing and the sheet will remain open.


From what I understand about the modal sheets, they need to be dismissed (to
avoid messing up with the main event loop).

The sheet can remain open for as long as you need it.

Keep in mind the user can open the sheet then go do something else for a couple minutes/hours/days/eons before coming back and hitting OK. So any background work you are doing needs to keep that in mind.


Can anyone advise on the two questions above, or at least inform if that is
possible to begin with.

If keeping a sheet open is not an option, I will go with the scenario of closing it and re-opening it again. In this case, how to implement the point
1 above - to have a red border around the text field.


Thanks,

Ron

--Nathan


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to