How can I pick-up a value from an INPUT field with no user interaction?

Current set-up : SPA Pages, Windows 10, MySQL, PHP

I have a Modal with a dynamic list, this can obviously change.
The number of Items (1) is populated dynamically from the database.
A calculation is then done on the form fields in the Modal.
The number of Items (1) is then multiplied by the Item Cost (2) which then gives a Line Total (3).
The Line Totals are then added together (using item.sum) to give a Grand Total (4).

This part all works great.

The problem is when I want to take the Grand Total figure (4), close the Modal and use that figure in a form field on the opener page. I can’t do this unless the user makes an additional selection/deselection. But the user may not want to change this selection and so does not interact with the form in any way.

This was previously confirmed by Patrick when he said "'dmx-on:updated' is triggered after the input value changed, but ONLY if it was a user action, it doesn’t trigger when it was changed by code."

So, in the 'Save & Close' button I CANNOT use
'modal_form.modal_grand_total_field.setValue(base_form.grand_total_field.value)'
because the figure was put there programmatically and not by user interaction.

Does anybody have a solution to this?

When you sum the items together could the result be assigned to a variable instead and the field on the modal has a dynamic attribute value of the variable value?

I tried something similar the other day. I will have another go to see what results.

Just another thought, I presume the initial database query has some base quantities & prices that can be adjusted using the form. Could you make a ‘default’ grand total that you assign as the default value of the variable
so the variable dynamic value would be something like
base_form.grand_total_field.value.default(serverconnect.data.basegrandtotal)
You could also then have a reset button that sets all the buttons back to the default, including the grand total.

Hi, Neil

If you need to implement your task with minimal transformations, I would go the following way:

  1. I made a setting For the modal window so that it can be closed only through the ‘Save & Close’ button (if this has not been done yet).

  2. Set the ‘Grand Total’ variable.

  3. I would hang a dynamic event On the ‘Save & Close’ button: assign the ‘Grand Total’ variable the value of the column sum (using item. sum) - the same principle that you use to calculate the value in cell (4).

  4. then, in the form field (where you want to use it), assign a value equal to the value of the ‘Grand Total’ variable.

The principle has a lot in common with what Ben suggests above.

@Mr.Rubi and @bpj Thanks for your help guys, I managed to sort this based on the ‘Save & Close’ button and a setValue and a ‘Grand Total’ variable. It works well.

As a side note, I do find that calculations (done in the way shown in my original post) are very slow.

1 Like