formie icon indicating copy to clipboard operation
formie copied to clipboard

getFieldValue() on submission throws error and I can't handle that in my template?

Open jishi opened this issue 1 month ago • 1 comments

Question

Deal with a submission that may or may not have a field? We have the same template rendering for multiple forms, and I need a way to just ignore a fetch of a field value if that field doesn't exist in the submit. Today it throws and renders a 500 error which is a bit odd, and I don't really know why.

Additional context

I basically do this:

{% set formSubmission = craft.formie.submissions.id(submissionId).one() %}
{% set teamName = formSubmission.getFieldValue('team') %}

This fails rendering if submission doesn't contain a team field, adding a default filter to it, still throws an error:

{% set teamName = formSubmission.getFieldValue('team')|default('') %}

And there is no real hasField() or similar. Also, I seem to lack documentation of available methods on the Submission element as well? According to documentation it has only attributes which seems wrong, it is also contradictory to your own articles.

jishi avatar May 16 '24 08:05 jishi