databasejoin default eval works only in form view

mauro

Member
Hi, maybe this could be a stupid question for an expert Fabrik user, but I'm unable to make a databasejoin element print a default value when the element value from the record is null and the user is in "details view"...
I tried to return a default value with some php code in the Default php evaluation field of the databasejoin element, and it works... But only in form edit view! In both the details view and list view the field value remains null...

How can I make so that Fabrik prints a php evaluated default value (when its value from the record is null) in all the views (list/details/form edit) ?

P.S.: for the list view, I tried to use the list plugin "php_events" to execute php code on the event onLoadData to prefill the databasejoin fields too when they are null... And it works, but of course only for the list view. How can I do that for the details view too?
 
Hi, troester,
thankyou very much for your suggestion.

My empty data is coming from some fields that are "always" empty (i.e. they are not saved in the db) because I use them just to print some other values derived from other fields. Now you could ask me why I don't use a calc field for that... I use a databasejoin field because for same derivated fields I need them to be displayed as a dropdown list of values (when in form edit view). I tried with the 'dropdown' element too, instead of a databasejoin, but the result was the same: the php default eval was executed only in the form view, not in the details view.

I tried to use the php form plugin, as you suggested, and now with something like that:

PHP:
 $formModel->data['myTable___myDbJoinField'] = ...someCalculatedID...;

in the details view I see now the raw ID instead of the related description field of the databasejoin element, but this is not a big problem, being that I can directly assign to the above variable the derivated description instead of its ID. But in the form view, the databasejoin element will always display "Please select", unless I return the calculated ID in the php default eval code of the dbjoin element too... So, to make the things work in all the 3 types of view (list/details/form edit), I have to use 3 different php snippets:

1) php_events plugin (in list) -> to display the default value in the list view.
2) php_form plugin (in form) -> to display the default value in details views.
3) php eval default field (in dbjoin element) -> to display the default value in the form edit view.

It's a little cumbersome, being that the default value should be the same in the 3 views... It would be much easier if the php default eval of the databasejoin element would be evaluated in details and list view too (when the values are empty)... In this way I could use 1 php snippet of code instead of 3 code snippets in 3 different places to make the same thing...
 
I think for a databasejoin element you have to set
$formModel->data['myTable___myDbJoinField_raw'] = ...someCalculatedID...;
 
Thanks troester, the "_raw" suffix did the trick! ;)

Maybe this could be useful to someone, so here is a template of php code I use in the form php plugin:

PHP:
$myDb = FabrikWorker::getDbo(false, 2); // <-- 2: connection ID of my db
$myQuery = $myDb->getQuery(true);

$myQuery
    ->select(array('detailTable.ID', 'descr'))
    ->from('detailTable')
    ->leftjoin('masterTable ON detailTable.masterID = masterTable.ID')
    ->where('ID = ' . $myDb->quote('{myTable___someID_raw}')); //in my case 'someID' is a databasejoin, so we take its raw value

$myDb->setQuery($myQuery);
$row = $myDb->LoadObject();

$formModel->data['myTable___myDbJoinField_raw'] = $row->ID;  // to make it work in the form view
$formModel->data['myTable___myDbJoinField'] = $row->descr; // to make it work in the details view

Of course, I always have to use the php_events plugin too for the list view, but at least now I have to use 2 php snippets instead of 3.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top