function of a table does not work in grid

14 views
Skip to first unread message

Giorgos Tsolakis

unread,
May 12, 2023, 1:27:36 PM5/12/23
to xata...@googlegroups.com
Hi all,

I have a function in the table "pail" that puts a leading zero to a one-digit number when I save a new entry.
<?php
class tables_pail {
    function beforeSave($record){
        $paildg = sprintf('%02d', $record->_values['paildigits']);
        $record->setValue('paildigits', $paildg);
    }
}
?>

This function works fine in the table "pail," but when I call this table as a widget grid inside table "locus", it doesn't work there. Among other things, I have tried copying the same code to "locus.php", but with no result. Can you please tell me what I am missing? 

Thank you! 

Steve Hannah

unread,
May 14, 2023, 11:13:08 AM5/14/23
to xata...@googlegroups.com
Yeah, this is a bit of a leak in the abstraction because adding related records doesn't actually go through the beforeSave hook.  You'll need to use the beforeAddRelatedRecord hook in the table that defines the relationship.

E.g.

function beforeAddRelatedRecord(Dataface_RelatedRecord $record) {
    if ($record->getRelationship()->getDomainTable() == 'pail') {
        $paildg = sprintf('%02d', $record->getValue('paildigits'));
--
You received this message because you are subscribed to the Google Groups "Xataface" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xataface+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xataface/CAF4gVnDQTZtpETGDyQdxHSKWb4YFzqiVCaySSkdaft2ssw56iw%40mail.gmail.com.


--
Steve Hannah
Web Lite Solutions Corp.
Reply all
Reply to author
Forward
0 new messages