Change value of Element after a calc field

Hey there,

I'm after a bit of advice about how to do something specific with an element which refers to a value of a calc field.

I have a calc element (which calculates a value from 2 dropdowns) and I want another element which then relates to this calc value.

The value I want to display is a word (which in the background relates to a number, which in turn relates to the calc value).

So if the calc value is the value of '1', I want to display 'Low' in an element to be displayed in the form and in details view. If the calc value is '5' I want to display 'moderate' and if the calc value is '10' I want to display 'high'.

So...

1 = Low
5 = Moderate
10 = High

Just not entirely sure how to go about this.

Edit, should also mention the calc element is done with AJAX if that makes any odds. Would also want this new element to set its value via AJAX as well.

Thank you
 
Last edited:
Well, the only way really is with another calc. But unfortunately you can use another calc's value (as a placeholder) in a calc, as there is no guarantee what order they will get run in, so you can't rely on the other calc having been processed.

So you'll just have to perform the same calculation in another calc, and just return the word instead of the number.

-- hugh
 
Hey Hugh,

Are you saying to just replace the current calc field I have to show the text rather than run 2 calc fields?

That actually makes more sense now I think about it.

I?m just not sure how the conditions would be set to show the text rather than a value.

So would I run some specific php code within the calc elements evalulation section to say ?if value == 10 then display low etc?

Thanks


Sent from my iPhone using Tapatalk
 
Well, it depends on whether you need that value anywhere else. If all you do with it is display something on the form, then you can just return the word rather than the value from your existing calc. If you use the number elsewhere, then add a second one.

What's the code of your existing calc?

-- hugh
 
Hey Hugh, we'd just need this value / word to appear in the form and also in the detail view for the record.

Current code is from one of the examples you put up.

$myCalc = (int) '{ra_list___add_1}' * '{ra_list___add_2}';
return $myCalc;

I was originally thinking this calculation would be hidden and then another element would determine the word and have that stored into the database, but if there is a simpler way and it can be just done in one calculation and this word recorded in the database, that would also work.
 
Code:
switch ((int) '{ra_list___add_1}' * '{ra_list___add_2}') {
   case 1:
      $myCalc "Low";
      break;
   case 5:
      $myCalc = "Moderate";
      break;
   case 10:
      $myCalc = "High";
      break;
}
return $myCalc;

That's if the values are exact, and you only ever get 1, 5 and 10 from that math, the switch will work. If it's ranges, you'll need to use an if then else structure.

-- hugh
 
Hey Hugh,

Thank you.

Yes there will be ranges so I?ll look at an if then else structure.

Thanks!


Sent from my iPhone using Tapatalk
 
Code:
$myCalc = (int) '{ra_list___add_1}' * '{ra_list___add_2}';

if ($myCalc < 5) {
      $myCalc = "Low";
}
else if ($myCalc < 10) {
      $myCalc = "Moderate";
}
else {
      $myCalc = "High";
}
return $myCalc;
 
Hey Hugh,

If the calculations were happening in a repeat group, how would I access the data to make the calculation? The repeat group is in a table, as opposed to a list.

I've run over the tutorials about repeating groups, but they seem like they are for an older version of Fabrik. I've tried going through the forums, but not really got anywhere.

Thanks
 
They should just work.

If the calc is in a repeat group, we make sure that any placeholder referencing an element in that same repeat group always has the data from the same instance of the repeat.

The problem with repeats in calc elements only happens if you are trying to access data from another repeat group, not the one the calc is in. As we then have no way of knowing which instance of that repeat you want.

-- hugh
 
Oh, the other issue is that if your calc is in a repeat and working with placeholders from the same group, you can ONLY access "this" instance of the repeat. You can't (for example) sum all repeated instances of an element.

-- hugh
 
Hey Hugh,

Yeah I tried just putting the calc in a repeating group but the calculation stopped working.

I had assumed that because the data was to be held in a new table that the element names would of changed. Is that the case?

The calculation is only being done within the repeating group.

Thanks


Sent from my iPhone using Tapatalk
 
The element names will be whatever it says they are in the list of elements. But yes, if you switched repeat on in the group, their names will have changed, to reflect the one-to-many joined table they are now in - so the prefix will be something like ra_list_123_repeat___ instead of just ra_list___ .

Just look at the elements list, in the "Full Element Name" column.

-- hugh
 
Sorru Hugh to bug you again, I've got the repeating group now working with the calc field. I didn't realise the element names just changed etc.

However, what I now have is the ability to create the repeating groups in the form (I created 3, all the results worked), but it doesn't seem to save the repeating groups into the database, or at least it doesn't show any of the other repeated groups, except the first record that I created in detail view, or when I go back to the form.

I did another record and it isn't saving anything at all, either showing in the detail view or when I go back and edit it in the form.
 
Hey Hugh,

I just created another list with grouping and that worked (without the calc), so i'll redo the list and form from scratch and see how that goes.

Will let you know how i go.

Thanks
 
Hey Hugh,

When using a repeat group, I noticed that all the records for the repeating group are shown in the list view by default (so if I add a new record, and repeat a group 3 times within the form and hit save, I have 3 records appear in the list with there parent id and the id).

Is there an option to just show the main record and not the 3 repeated groups I added? (but then obviously show all the data for the repeated group). I couldn't see any option for it.

Thank you.

Screen shot shows what I mean.
 

Attachments

  • Screen Shot 2017-10-15 at 2.47.32 pm.png
    Screen Shot 2017-10-15 at 2.47.32 pm.png
    122 KB · Views: 38
List settings, Data settings, in the Joins tab. Option for how to render joined data. Set it to either "Merge" or "Merge and reduce".

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top