issue with calc field

FilMar

Member
What is wrong with the following code in a calc field?

Code:
$test = '{bc_lesrooster___lesdag_raw}';
if ($test == '0') {
  $lDag = 'dagelijks';
  } else {
  $lDag = '{bc_lesrooster___lesdag}';
  }

return $lDag;

the field bc_lesrooster___lesdag is a dropdown with numbers as values and text as labels

In the form everything is good but in the list it shows ok (dagelijks) when the value is 0 but it shows the values in place of the labels in the other cases...

I found something strange (or maybe not):
when i have the 3 calc buttons off, i have this faulty result but I see it directly in the list (for existing records)
when I have the first calc button (Only calc on save) on, I get the correct result but only after I open each line and save it, otherwise I have nothing in the list.

So with new records I should have no problem, I see it now with a new calc field and some exisiting records. But I find it strange.

Any advice?


Greetings,

Filip
 
Can you please turn on fabrik debugging and call the list with ?fabrikdebug=1 or &fabrikdebug=1 appended to the URL and see if the debugging information shows numbers?

If you cannot see what the cause is, please save the web page with fabrikdebug=1 as an HTML file and upload it here (you may need to add .txt to the end of the filename to get it to upload.

(Once you have done this, try setting Calc Only On Save = Yes and see if that is a workaround.)
 
@Sophist: I did what you proposed but it is not that clear where I can see the information. I suppose it is under the table:data block and there it is showing numbers for both values
Code:
...
[bc_lesrooster___lesdag] => 3                                                               this should show Woensdag
[bc_lesrooster___lesdag_raw] => 3
...
[bc_lesrooster___wanneer] => 3
[bc_lesrooster___wanneer_raw] => 3
...

Now I made the field also visible in the list and now it shows the correct value for the field but still wrong in the calc field (I also concatenate some other fields now in the calc)

Code:
....                  
[bc_lesrooster___lesdag] => Woensdag
[bc_lesrooster___lesdag_raw] => 3
[bc_lesrooster___lesuur_begin] => 14:00:00
[bc_lesrooster___lesuur_begin_raw] => 14:00:00
[bc_lesrooster___lesuur_einde] => 15:15:00
[bc_lesrooster___lesuur_einde_raw] => 15:15:00
[bc_lesrooster___wanneer] => 3 14:00-15:15                                           --> this should show Woensdag 14:00-15:15
[bc_lesrooster___wanneer_raw] => 3 14:00-15:15

And yes, Calc only on Save = Yes is a workaround but then I have to edit each record and save it to get the correct data.

the file should be attached. and some screenshots
  • lesdag shows the dropdown field
  • wanneer the calc field
  • List is how it shows in the list
  • form shows a part of the form


Many thanks in advance,

Filip
 

Attachments

  • BalanCirk_Test.html.txt
    263.3 KB · Views: 10
  • lesdag.png
    lesdag.png
    16.3 KB · Views: 11
  • wanneer.png
    wanneer.png
    15.8 KB · Views: 11
  • list.png
    list.png
    5.8 KB · Views: 9
  • form.png
    form.png
    3.8 KB · Views: 10
Last edited:
Thanks for the fabrikdebug which was very helpful.

I have the answer - which is that the dropdown element is not suitable for what you are trying to do. You need to create a reference table with the dropdown values and labels, and swap your field to use that.

Then the calc will get the right values.
 
P.S. I always use reference tables and databasejoins because they are far more flexible and you avoid these sorts of problems.
 
OK, no problem.

And, what's more. I did already have that table, I don't know why I didn't used it here...

Greetings,

Filip
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top