Forum

Thread tagged as: Question, Forms, Shop

Currency Swap in Shop without Submit

Hi,

I am trying to get a currency swap select to work in Shop, without needing a submit button. The form is triggering a refresh when I change select option, but the currency is not changing and debug is showing the old currency as still active. I have this:

TEMPLATE

<perch:form id="currency" method="post" app="perch_shop">
    <div>
        <perch:label for="currency">Currency</perch:label>
        <perch:input type="select" options="<perch:shop id="currency_list" />" id="currency" required="true" class="autosubmit"  />
    </div>
</perch:form>

OUTPUTTED HTML

<form id="form1_currency" action="/" method="post">
    <div>
        <label for="form1_currency">Currency</label>
        <select id="form1_currency" name="currency" class="autosubmit" required="required"><option value="47">GBP</option><option value="44">EUR</option><option value="142">USD</option></select>
    </div>
</form>

JQUERY

$('.autosubmit').on('change', function(){
  console.log('something changed');
    $(this).closest('form').submit();
});

This might be a bit out of scope for support but would be great if you could take a look

Mike Harrison

Mike Harrison 37 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you don't use a Perch form submit button, you need to include the hidden control field:

<perch:input type="cms" />

But it might be better to include a proper submit button and then hide it with JavaScript. That way, if the JavaScript doesn't run for whatever reason, the form will still work.

Thanks Drew that worked perfectly. And thanks for the tip on hiding the submit, I will do that