I collect data in a web form. As one of the first fields, it has a dropdown with which it selects a certain ID. Later on, there shall be grouped elements like this:

value_old | value_new | diff

value_new is just the new value, that the user shall provide.

diff is the computed difference value_new - value_old and I think that I can implement that as a "Computed Twig" element.

value_old is a bit more complex. This should be the value_new from the newest submission already in the database for the same form, where the ID from the dropdown in the beginning was the same.

I think, the solution should go in a direction of a token definition for the value_old or so, but I'm not sure on whether this is a) the right direction and b) how this could be done.

  • Probably, it's important that I only need to show the value_old and use it for diff, but I don't need to store it again.
    – flauschi
    Dec 7, 2020 at 21:06
  • 1
    Not done yet, but it seems like that it's a possibility to add a view element to the webform and define a view that gives the right information, using the "Webform View" module. Would have started earlier with this, if there wouldn't be an explicit reference to the 8.x-5.x version which might not even be incomplete, but plain wrong, if I saw it correctly on the issue tracker.
    – flauschi
    Dec 7, 2020 at 21:35

1 Answer 1


Long story short:

I wrote a custom webform element that takes an argument that gets updated via AJAX and queries the database.

Long story:

As in my comment, adding the "Webform View" module worked besides the wrong version number in the project description for the dependencies.

But it didn't help.

So, here are a few learnings along the way that might be interesting for people with similar challenges, followed by the final solution.

I was able to create a view that outputs the value_old that I need, when I provided the previously selected ID as an argument.


While there is a webform element that shows views and takes arguments, it doesn't work with a token as an argument to reload it's content, when there is a (new) value for the token. It is even not possible to split it up into several pages, such that there is already a value for the token, when the user proceeds to the next page.

I needed a webform element that gets recalculated, when the form changes, but gets its information from the database. So, I created a new webform element in a custom module. I took the „Computed Twig Element“ as a starting point. But instead of doing a computation, I took the input value as an argument for querying the database for my value_old.

In theory, it would have been possible, to use the view from above, as long as computed values in this view are stored in the database. If they aren't, querying the view will run out of memory.

In my case, there are some additional requirements to the rights management. Therefore, I tried different querying mechanisms. In this custom field, it was possible to query the database directly and to query the view. I also tried the Webform Query module. But something in there seems broken, because this module produced a query with a wrong name in it, as soon as I started querying for ordered results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.