Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 617299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:25:15+00:00 2026-05-13T18:25:15+00:00

I would like to solicit additional information from the user during the NSOpenPanel but

  • 0

I would like to solicit additional information from the user during the NSOpenPanel but need to validate that information before the open panel completes. For example, I may want to allow the user to add a note about the file in the open panel selection but need to validate that that comment is not empty.

I have an accessory view whose controls are bound to an NSObjectController whose content object in turn is bound to the represented object of the NSViewController that I use to load the accessory view’s nib. The represented object has NSKeyValueCoding-compliant validation methods (e.g. -(BOOL)validateKey:error:). Validation is correctly handled (and violations reported via modal dialog) when the user modifies the values of the controls.

My problem is that I can’t figure out how to get validation if the user doesn’t enter anything in the accessory view. For example, say I have a single text field in the accessory view whose bound object validates that the text is non-zero in length. If the user enters text (validation succeeds), then deletes the text, validation fails and the user is presented with the error. However, if the user doesn’t enter text, the open panel dismisses without error. How can I validate that the text is non-zero before the open panel dismisses?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:25:15+00:00Added an answer on May 13, 2026 at 6:25 pm

    You should register your controller as the open panel’s delegate and then implement the -panel:isValidFilename: delegate method. Returning NO from that method allows you to prevent the open dialog from being closed:

    - (BOOL)panel:(id)sender isValidFilename:(NSString *)filename
    {
        //validate the field in some way, in this case by making sure it's not empty
        if([[textField stringValue] length] == 0)
        {
            //let the user know they need to do something
            NSAlert *alert = [[NSAlert alloc] init];
            [alert setMessageText:@"Please enter some text."];
            [alert addButtonWithTitle:@"OK"];
            [alert beginSheetModalForWindow:sender modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
            //return NO to prevent the open panel from completing
            return NO;
        }
        //otherwise, allow the open panel to close
        return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
Would like a for loop in jquery so that: For every hover_link: show hidden
Would like to make anapplication in Java that will not automatically parse parameters used
Would like to do this: letters: charset ABCDEFGHIJKLMNOPQRSTUVWXYZ pick letters 2 but pick doesn't
Would like to know from all you guys what do you think about my
Would like to implement some solution for adding tags to a certain user profile
would like your comments. Eg: When user first visit www.testing.com/productdetailpage.asp I will use caching-
Would like to know if there is any resource on the web that conveniently
would like to create a function that generates graphs using ggplot. For the sake
would like to match urls which are outside the comment function from javascript. Regex

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.