Turning off required validation of not null fields?

A place for users and developers of the Xataface to discuss and receive support.

Turning off required validation of not null fields?

Postby 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.
igormt
 
Posts: 5
Joined: Sat Aug 27, 2011 9:17 am

Re: Turning off required validation of not null fields?

Postby shannah » Sun Aug 28, 2011 6:48 am

This may be a bug. Try
validators:required="false"
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Turning off required validation of not null fields?

Postby 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.
igormt
 
Posts: 5
Joined: Sat Aug 27, 2011 9:17 am

Re: Turning off required validation of not null fields?

Postby 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
FractalizeR
 
Posts: 19
Joined: Tue Oct 04, 2011 5:26 am

Re: Turning off required validation of not null fields?

Postby shannah » Thu Oct 06, 2011 10:02 am

Try validators:required="false"
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: Turning off required validation of not null fields?

Postby 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?
FractalizeR
 
Posts: 19
Joined: Tue Oct 04, 2011 5:26 am

Re: Turning off required validation of not null fields?

Postby shannah » Tue Oct 11, 2011 4:14 pm

Fixed in SVN and 1.3.x branch.

http://bugs.weblite.ca/view.php?id=856
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 7 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved