Page 1 of 1

Turning off required validation of not null fields?

PostPosted: Sat Aug 27, 2011 9:35 am
by igormt
Hi,

The documentation says you can turn off the "required" validator for a "not null" field by setting validators:required=0 in the fields.ini file.

In 1.3rc6, this doesn't seem to work as advertised. I created the following test case:

The table is:

CREATE TABLE `test3` (
`test3Id` int(11) NOT NULL DEFAULT '0',
`test1Id` int(11) DEFAULT NULL,
`test2Id` int(11) DEFAULT NULL,
`name` text COLLATE latin1_general_cs,
`number` double NOT NULL,
PRIMARY KEY (`test3Id`)
);

And the corresponding fields.ini file is:

[test3Id]

[test1Id]

[test2Id]

[name]
widget:label = "The name"

[number]
validators:required=0
widget:label = "The number"

When I go to add a new record to table test3, the "number" field displays with the little red "required" dot and triggers the required validator error if I leave it blank.

What am I doing wrong?

For context, the reason I want to do this is that in my application that widget is hidden and the value for the field is computed in a "beforeSave" action. But what happens is that before the trigger action has an opportunity to fill in the value, I get an error that a required value is null. I also tried setting a validator the table delegate class, also with no success in avoiding the error that a required value is missing.

For completeness, the corresponding table delegate class with these actions is:

test3.php:
<?
class tables_test3
{
function beforeSave( &$record )
{
$record->setValue( 'number', 101.101 );
}

function number__validate( &$record, $value, &$params )
{
return true;
}
}
?>

Note also that if I alter table test3 so that field number is allowed to be null, then everything works as intended. How do I make the default "required" validator go away?

Thanks.

Re: Turning off required validation of not null fields?

PostPosted: Sun Aug 28, 2011 6:48 am
by shannah
This may be a bug. Try
validators:required="false"

Re: Turning off required validation of not null fields?

PostPosted: Sun Aug 28, 2011 9:33 am
by igormt
Unfortunately that doesn't work either. Shall I submit a bug report on the bug tracker?

BTW, xataface is a really impressive tool. You've saved me weeks (if not months) of time.

Thanks.

Re: Turning off required validation of not null fields?

PostPosted: Thu Oct 06, 2011 3:13 am
by FractalizeR
I can confirm, that it doesn't work in 1.3rc6. Is there any workaround?
Filed bug report: http://bugs.weblite.ca/view.php?id=856

Re: Turning off required validation of not null fields?

PostPosted: Thu Oct 06, 2011 10:02 am
by shannah
Try validators:required="false"

Re: Turning off required validation of not null fields?

PostPosted: Thu Oct 06, 2011 12:49 pm
by FractalizeR
shannah wrote:Try validators:required="false"


Like igormt says, that doesn't work either. Can I patch anything in Xataface source to make it working?

Re: Turning off required validation of not null fields?

PostPosted: Tue Oct 11, 2011 4:14 pm
by shannah
Fixed in SVN and 1.3.x branch.

http://bugs.weblite.ca/view.php?id=856