Sterc / FormIt

A dynamic form processing Snippet for MODX Revolution
https://docs.modx.com/current/en/extras/formit
33 stars 58 forks source link

Wrong country "selected" if FormItCountryOptions snippet is used twice in same form #255

Open gadgetto opened 3 years ago

gadgetto commented 3 years ago

Bug report

Summary

If the FormItCountryOptions snippet is used twice within the same form, the second snippet call selects the wrong country. It always selects the country from the first snippet call.

I tested the correct placeholder output with a hidden field. The placeholder data is correct - only the FormItCountryOptions snippet selects the wrong country.

This wasn't a problem in previous FormIt versions. I don't know which update introduced this bug.

Step to reproduce

...
<select class="form-control" name="country" id="country">
    <option value="" [[!+upd.country:is=``:then=`selected="selected"`]]>Land wählen</option>
    [[!FormItCountryOptions?
        &selected=`[[!+upd.country]]`
        &prioritized=`[[++country_priorisation]]`
        &limited=`[[++country_limitation]]`
        &country=`de`
   ]]
</select>
.....
...
..
<select class="form-control" name="country2" id="country2">
    <option value="" [[!+upd.country2:is=``:then=`selected="selected"`]]>Land wählen</option>
    [[!FormItCountryOptions?
        &selected=`[[!+upd.country2]]`
        &prioritized=`[[++country_priorisation]]`
        &limited=`[[++country_limitation]]`
        &country=`de`
   ]]
</select>
...

Environment

MODX 2.7.3-pl FormIt 4.2.6-pl

gadgetto commented 3 years ago

As this problem exists on a big webshop we built, I'd be very thankful if you could provide a quick hint on how to fix this!

gadgetto commented 3 years ago

@halftrainedharry posted a partial fix in MODX forums:

https://community.modx.com/t/solved-wrong-country-selected-if-formitcountryoptions-snippet-is-used-twice-in-same-form/4545/5