Turning off required validation of not null fields?
Posted: Sat Aug 27, 2011 9:35 am
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.
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.