Turning off required validation of not null fields?
Archived from the Xataface Users forum.
igormt — 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.
shannah — Sun Aug 28, 2011 6:48 am
This may be a bug. Try
validators:required=”false”
igormt — Sun Aug 28, 2011 9:33 am
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.
FractalizeR — Thu Oct 06, 2011 3:13 am
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
shannah — Thu Oct 06, 2011 10:02 am
Try validators:required=”false”
FractalizeR — Thu Oct 06, 2011 12:49 pm
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?
shannah — Tue Oct 11, 2011 4:14 pm
Fixed in SVN and 1.3.x branch.