質問

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.

役に立ちましたか?

解決

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.

But:

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.

ライセンス: CC-BY-SA帰属
所属していません drupal.stackexchange
scroll top