• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: modal sheet with validation logic
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: modal sheet with validation logic


  • Subject: Re: modal sheet with validation logic
  • From: Nathan Kinsinger <email@hidden>
  • Date: Wed, 31 Dec 2008 11:56:09 -0700

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 (email@hidden)

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:
This email sent to email@hidden


References: 
 >modal sheet with validation logic (From: "Ronnie B" <email@hidden>)

  • Prev by Date: Re: modifier key query
  • Next by Date: mydoc.myext/QuickLook/Preview.html and full screen
  • Previous by thread: modal sheet with validation logic
  • Next by thread: NSTableView headers
  • Index(es):
    • Date
    • Thread