Skip navigation.
 
mlNSForm validation
FROM : James Powell
DATE : Tue Nov 12 22:40:00 2002

I've looked through the list archives to no avail.

I am working with a preferences dialog which displays a handful of
NSForms for the user to fill in.

Q1:

This code gives me a warning, "invalid conversion from 'const
NSFormCell*' to 'NSCell*'" on the second line.

   cells[0] = [m_GridSizeForm cellAtIndex:0];
   [m_GridSizeForm selectCell:cells[0]]; // warning here

Besides casting the cell argument, is there a better way to select the
cell?  Why is casting an NSFormCell instance to NSCell invalid?

Q2:

NSFormatter's setMinimum and setMaximum messages take an
NSDecimalNumber * argument.  Is there a way to initialize an
NSDecimalNumber directly using an int?

In the archives, it is suggested that we use:
   NSDecimalNumber *foo = (NSDecimalNumber *)[NSDecimalNumber
numberWithInt:1];

This works, but that downcast makes me nervous.  What's up with that? 
Should I use it?  Does anyone else agree that NSDecimalNumber should
have a decimalNumberWithInt message?

Q3:

The user brings up my preferences dialog.  It is modal, it is a sheet. 
NSForms are there, and they are mostly numeric in content.  The user
changes a field to an invalid value: below minimum, above maximum, or
non-numeric.  The user hits <tab> to proceed to the next field.  A red
error message in an NSTextField appears saying for example "The minimum
value is 100."  The cursor remains in the field that has an invalid
value, because my control:didFailToFormatString:errorDescription:
returns NO.

The user closes the preferences window.  An alert appears reading
"There are invalid values in this form.  Please correct them, or press
Cancel to void all changes.".  The user presses Cancel.

The user re-opens the preferences window.  It is exactly where she left
it, with the cursor in the field with the invalid value, and the red
error message evident.

This is %99 of the behavior I want.  The only problem is the last step.
  When the user reopens the preferences dialog, I want the original,
valid values in all of the NSFormCells.  When the prefs window is
reopened I am replacing the values in all of the form cells by calling
for example:

   cells[0] = [m_RecordingForm cellAtIndex:0];
   [cells[0] setDoubleValue:[GetTask()->GetController() recordingFPS]];

This message doesn't seem to be enough to reset the state of the cell
which has the invalid value in it.  It seems like setDoubleValue:
should override the user's edits, but it does not appear to.  Is there
any way to ask a cell to default back to the last known good value, or
to override the editing state of a cell?

Thanks much,
  James


Related mailsAuthorDate
mlNSForm validation James Powell Nov 12, 22:40
mlRe: NSForm validation James Powell Nov 13, 11:31
mlRe: NSForm validation Andreas Mayer Nov 13, 13:23
mlRe: NSForm validation James Powell Nov 13, 14:09
mlRe: NSForm validation Andreas Mayer Nov 13, 15:49
mlRe: numberWithInt (was Re: NSForm validation) Cameron Hayne Nov 13, 16:35
mlRe: numberWithInt (was Re: NSForm validation) Jeff Disher Nov 13, 16:52
mlRe: numberWithInt (was Re: NSForm validation) Andreas Mayer Nov 13, 17:16
mlRe: numberWithInt (was Re: NSForm validation) Andreas Mayer Nov 13, 17:45
mlRe: numberWithInt (was Re: NSForm validation) Andreas Mayer Nov 13, 17:53
mlRe: numberWithInt (was Re: NSForm validation) James Powell Nov 13, 18:11
mlRe: numberWithInt (was Re: NSForm validation) Andy Lee Nov 13, 20:08
mlRe: numberWithInt (was Re: NSForm validation) Andreas Mayer Nov 14, 06:49
mlRe: numberWithInt (was Re: NSForm validation) Andy Lee Nov 14, 08:30
mlRe: numberWithInt (was Re: NSForm validation) Andreas Mayer Nov 14, 13:17