CalcBuilder Forum

Inline results with Sections

User kahen 2016-06-15 02:57:48

Hello,

Inline results are not showing actual results when I activate sections. Normally it shows however my customers might want to add more rows of my fields and I need section for that. When I activate sections inline results are just keep refreshing and when I enter values in the fields nothing happens.

What could be the reason for this?

Moonsoft support 2016-06-15 08:46:33

Hello,
we guess you're trying to show some inline results inside the section, right? Then you must change a little bit the way to specify outputs, because when using sections, you will have many results to return, one per line.

Let's say you have a default input with 2 fields(input1 and input2), and an inline field (myinlineresult). You have at the code section, for ex:


$myinlineresult=$input1*$input2;


This will work on a default form. Now if you decide to include the 3 fields inside a section, you will have a list of inputs, so you should return a list of outputs. So the inputs will be

$input1 and $input2 //for the first line
$input1 and $input2 //for the second line
...
$input1 and $input2 //for the nth+1 line


at the code you need to specify the result will be a list (array):

$myinlineresult=array();


and then fill the values of each line

$myinlineresult=$input1*$input2;
$myinlineresult=$input1*$input2;

...etc

as you probably don't know exactly how many lines your user will add to your form, you can do a loop to run over all lines of the inputs, this way:


$myinlineresult=array();

///as the forum strips out some tags of the code, please follow this explanation at this new entry of the tutorial section:

https://www.moonsoft.es/easyblog/entry/55-working-with-sections-inputs-and-inline-results

Thank you

Edited by MSTeam - 15.06.2016 09:00

User kahen 2016-06-15 14:00:36

wow! Many thanks for the prompt reply! I will give it a try and comeback if it works.

User kahen 2016-06-17 02:25:24

I think I could not make it work :)

Is it possible to upload an example calculator so I can apply it to mine ?

User kahen 2016-06-17 03:06:17

Well. I made your example working and see if I can apply it to my version :)

I also made an example calculator. You guys can download it from the link below;

https://drive.google.com/open?id=0B_RFt-SnVsEYNnItLUxCRDlhaGM

To be honest anything could be done with this component after couple of modifications. Very well made!

User kahen 2016-06-17 03:18:45

Another question.

What if we are using matrix table and wanted to use sections with inline results each line? What should we do then?

User kahen 2016-06-17 03:34:52

One more thing. I include a field for this calculator but it is optional for my users. When I apply your solution and If I or any user dont enter any value on that optional field calculator does not work and it only shows refreshing icon. When I enter value in that optional field it works on each line or section.

How can we bypass this optional field if it is not filled?

I asked many questions but I am very curious to apply my calculator online.

Waiting your reply.

thank you.

Moonsoft support 2016-06-17 10:07:53

Another question.

What if we are using matrix table and wanted to use sections with inline results each line? What should we do then?


Hi,
there's no problem to use matrix to calculate results inside or outside the sections, you only need to use the proper index for rows/columns for each case, so if you had for ex, this line to get one matrix data according to your inputs:

$auxdata=$mymatrix;

and now you insert your inputs inside a section, like we've commented above, you only need to use the list syntax for them:

$auxdata=$mymatrix]];


you can replace the 0 for the dynamic $i index explained above inside the loop.


Hope this helps, regards

Moonsoft support 2016-06-17 10:10:42

One more thing. I include a field for this calculator but it is optional for my users. When I apply your solution and If I or any user dont enter any value on that optional field calculator does not work and it only shows refreshing icon. When I enter value in that optional field it works on each line or section.

How can we bypass this optional field if it is not filled?

I asked many questions but I am very curious to apply my calculator online.

Waiting your reply.

thank you.


Hi,
if the calculator doesn't come back it means it may be getting an error when trying to execute your calculations. Maybe you've set the field as 'optional' but you're using it inside your calculations so they don't work if is empty? Please double check your math expressions to find out if that field is really needed for all cases, you can place a ticket and share your calculator if you can't get it working, we'll take a look and let you know how to fix.

Regards

User kahen 2016-06-17 11:57:45

One more thing. I include a field for this calculator but it is optional for my users. When I apply your solution and If I or any user dont enter any value on that optional field calculator does not work and it only shows refreshing icon. When I enter value in that optional field it works on each line or section.

How can we bypass this optional field if it is not filled?

I asked many questions but I am very curious to apply my calculator online.

Waiting your reply.

thank you.

Hi,
if the calculator doesn't come back it means it may be getting an error when trying to execute your calculations. Maybe you've set the field as 'optional' but you're using it inside your calculations so they don't work if is empty? Please double check your math expressions to find out if that field is really needed for all cases, you can place a ticket and share your calculator if you can't get it working, we'll take a look and let you know how to fix.

Regards


Many thanks for your prompt replies.

I am using it in my calculations because sometimes users need to enter values and sometimes not. It depends on the product they want.

My calculator calculates weight of 1 pc of Plastic bag.

Fields I am using;

Width (Necessary)
Length (Necessary)
Bottom Gusset (Optional)
Thickness (Necessary)

so sometimes customers might want a bag with bottom gusset and sometimes not (Please Google bottom gusset if its unclear what it means). If they dont want it they will leave it empty as usual but calc does not return with result in this case.

Edited by kahen - 17.06.2016 11:58

Moonsoft support 2016-06-18 10:53:39

Hi,
ok, we understand the function you want to build. The problem may be your field is optional but you're always using it at your calculation code (so it throws an error if empty)? Depending on your calculator specs, you may need to add any condition at your code so you can perform different calculation in case the optional field is filled or not, if your field is called for ex 'bottom' you can add to your code an 'if/else' block:

if($bottom==""){

//here your calculations in case the field is empty
}
else{
//here your calculations in case the field has any value
}

so you can ensure you don't use the field $bottom inside the section where you know already the field is empty.

Hope this helps, regards

User kahen 2016-06-20 13:29:37

Hi,
ok, we understand the function you want to build. The problem may be your field is optional but you're always using it at your calculation code (so it throws an error if empty)? Depending on your calculator specs, you may need to add any condition at your code so you can perform different calculation in case the optional field is filled or not, if your field is called for ex 'bottom' you can add to your code an 'if/else' block:

if($bottom==""){

//here your calculations in case the field is empty
}
else{
//here your calculations in case the field has any value
}

so you can ensure you don't use the field $bottom inside the section where you know already the field is empty.

Hope this helps, regards


Hi,

Thank you for your solution. I thought "if / else" solution as well but it looked complicated to me. so I found something very simple.

If I enter 0 to my field, my calculator starts working as there is a number entered in the value. So I added this simple javascript code into my calculator;

cb_setValue('alt','0');

(alt is the name of my field)

so Default value of the optional field is 0 to make calculator work in case users want to change it.

Moonsoft support 2016-06-20 17:17:24

Hi,
ok, if a default value does the work for your calculator, then you don't need to add js, there is a 'default value' parameter that you can set for each field at your calculator backend->fields tab.

Regards

User kahen 2016-06-20 19:18:08

Oh! I havent seen that option and didnt know that it was giving values to fields! Works like a charm now and solved my problem without js.

Thank you for your patience and help :)

User kahen 2016-06-23 16:37:07

Hello,

Its me again!

I am stuck at something.

Is it possible to make a formula of 2 Inline fields and make the formula repeat each time when user clicks add button?

For example lets say I have inline1 and inline2

I want to make $inline3=$inline1*$inline2

Hope I explained clearly.

Edited by kahen - 23.06.2016 17:42

Moonsoft support 2016-06-23 21:08:12

Hi,
yes, you can use at your formulas any inline field, results previously calculated or any other variable. The inline calculations will launch everytime you add one section so you only need to add your code to have it working. You only need to ensure you place your code:

$inline3=$inline1*$inline2;

below the other formulas where you calculate values for inline1 and inline2, so the values are already there when you calculate inline3.

Hope this helps, regards

...
Support/development 40 hours

With the peace of mind of having a professional team at your service (20% discount)

Buy now!
...
Support/development 10 hours

Get a bigger amount of hours for more complex tasks and get a 10% discount

Buy now!