lewisjenkins / craft-dynamic-fields

Populate Craft fields with dynamic data using the power of Twig.
Other
147 stars 11 forks source link

Incompatible with Guest Entries (possibly any front-end form) #37

Closed johndwells closed 3 years ago

johndwells commented 4 years ago

I am trying to use a Dynamic Dropdown field in a Guest Entries form (https://github.com/craftcms/guest-entries) but the default values are always saved on the new entry.

I've tracked it down to this part of Dropdown::normalizeValue():

if ($this->isFresh($element) ) :
    foreach ($options as $key => $option) :
        if (!empty($option['default'])) :
            $value = $option['value'];
        endif;
    endforeach;
endif;

isFresh() is evaluating to true, because on the front-end there hasn't been a draft/revision created (unlike how Craft 3.2+? behaves). And because it evaluates to true, it sets the value to the default, overriding what value was passed to it.

I'd be happy to submit a pull request if you think this is correct?!