umbraco / Umbraco.Forms.Issues

Public issue tracker for Umbraco Forms
29 stars 0 forks source link

Inconsistent Prevalue Source Behaviour #1221

Closed Attackmonkey closed 3 days ago

Attackmonkey commented 1 month ago

We are trying to build a prevalue source that is form/field sensitive. We have a number of forms where field values must be pulled from Salesforce, but we don't want to have to set up a prevalue for every question, as that would mean we could end up with hundreds if not thousands of prevalue sources.

Our plan was to have a custom setting on the fields and in the prevalue source, tweak the returned prevalues based on the field settings so we can just have one prevalue source, as that seems much tidier.

The GetPrevalues method on a Preview accepts a Form and a Field parameter. Which we can can happily access and return tailored prevalues for on the front end of the forms. However in the back end, both the field and the form are null, when fetching prevalues in both the design view AND the edit view.

I'd expect the form and field to be null when designing the form, as the form may not have been created yet, however, for editing form entries, I'd expect the form and field to be available, as both the form and the field are known.

Looking at the HTTP requests, on the form record edit page, it just fetches the prevalue by it's GUID, and doesn't pass in the field or form Id.

Reproduction

Create a Prevalue source that only returns values if the field or form are not null. Assign that prevalue to a dropdown field. On the front end you'll see prevalues in the dropdown. When editing the records in the CMS, you'll see the prevalues aren't populated.

Bug summary

Form and Field should really be available to the GetPrevalues method when called from the records editor in the CMS.

Expected result

Front end and back end record editor calls to the GetPrevalues method should be consistent, so that adding and editing in the CMS work the same.

Actual result

You are unable to edit the dropdown in the CMS records editor if your Prevalue Source has a dependency on either the form or the field.

If it's not possible to do this, we should probably update the docs to make it clear that the form and field parameters are ONLY available on the front end.

AndyButland commented 1 month ago

Just had a quick look into this and can verify what you have found. Also agree that this should be possible.

As you say, the method does access a form and field, so you could customise the result based on that. They are both nullable though, and aren't currently populated from the backoffice UI.

AndyButland commented 3 days ago

We will be adding support for customising the list of prevalues when editing and previewing the form field in the next minor releases.