Use Javascript to get sum (avoid calling an action)

Use Javascript to get sum (avoid calling an action)

  

Hi everyone, I'm in need of some help;

what I'm tring to achieve is to sum two addends inside a table-records only via javascript (avoiding to call an action).

I've attached a small oml to show you what I mean.

What you'll find inside the oml is a basic table with two input texts (to insert the addends values) and an expression which will be the sum of those two addends. I put an onkeyup property on each input text, but it does'nt work properly.

Can you help me out?

Cheers,
Jim



Hi Jim,

Unfortunately, what you're trying to do is not the "OutSystems way" of doing things. OutSystems is a low code toolchain, and you are trying to bolt "high code" onto it. On today's modern infrastructures, there's hardly any reason to not call an Action to avoid some (very, very slight) overhead.

What you should do instead: set the On Change Property of both Inputs to a Screen Action. Inside the Screen Action, sum the two numbers, and assign it to SumTable.List.Current.Sum.Total. Then Ajax Refresh the Total Expression.

Kilian Hekhuis wrote:

Hi Jim,

Unfortunately, what you're trying to do is not the "OutSystems way" of doing things. OutSystems is a low code toolchain, and you are trying to bolt "high code" onto it. On today's modern infrastructures, there's hardly any reason to not call an Action to avoid some (very, very slight) overhead.

What you should do instead: set the On Change Property of both Inputs to a Screen Action. Inside the Screen Action, sum the two numbers, and assign it to SumTable.List.Current.Sum.Total. Then Ajax Refresh the Total Expression.

Hi Kilian, thank you for the quick reply.

I know that calling an action and refreshing would be the right way, but my case is a little bit different; imagine having a lot of input texts and a lot of calculated attributes (the pic attached shows just a part of it). Everytime i insert a value I have to trigger an on-change action to calculate the total results of my expressions, and calling an action every time slows down the process.

I tought that there might be an easier way to do so. I'm I wrong?

Hi Jim,

It seems you are falling for a case of Permatur Optimization™. Unless you actually experienced it being very slow, there's no need to start optimizing things (in a way not in alignment with the Platform's goals!). Todays networks are fast. Todays computers are very, very fast. Even adding a million numbers should happen in the blink of an eye. So please, don't "optimize" unless you hit a speed bump. Until then, do it the Proper Way™.

Ok Kilian, I got your point.
Thanks anyway for your help and time.

Cheers,
Jim

Hi,

I'm working on project where I have to do lot of client side code, they wan't minimize server requests. You can define a class for the inputs based on row number, for exemple input1_row1 and input2_row1, input1_row2 and input2_row2, and so on.Then you need a javascript function with 2 parameters, one for each input class, then you can get inputs value using jquery and do the sum.