The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Setting up conditional custom fields

PhilippePhilippe Member
Hi,

I am trying to set up some custom fields that are language dependent. The idea is to pass h:lang in the order form and then set the relevant fields visibility to "visible"

Can you help figure out what is wrong with the code below ? (if necessary, test page here:
http://www.enus.i-sails.com/testsimple.html

(use bottom buttons which include an h:lang)



<fieldset id="fc_custom_fields">

<div class="fc_inner">
<div id="FrenchCustomFields" style="visibility: hidden">
<p>French stuff </p>
</div>

<div id="SpanishCustomFields" style="visibility: hidden">
<p>Spanish stuff </p>
</div>


<script type="text/javascript" charset="utf-8">
if (fc_custom_fields.lang == "fr")
{
document.getElementById("FrenchCustomFields").style.visibility = "visible";
}
</script>


</div>
<!-- .fc_inner -->
</fieldset>
<!-- #fc_custom_fields -->
Comments
  • fc_adamfc_adam FoxyCart Team
    @Philippe,

    Thanks for including your code. There are a couple issues at play here, but primarily that fc_custom_fields isn't a standard variable we output, and with how 2.0 works with re-rendering within twig, any changes you apply by javascript will most probably be lost.

    Instead I'd recommend applying it like this:
    {% set custom_lang = "EN" %}
    {% for key, item in custom_fields %}
    {% if key == "lang" %}
    {% set custom_lang = item.value|upper %}
    {% endif %}
    {% endfor %}

    <fieldset id="fc_custom_fields">
    <div class="fc_inner">
    {% if custom_lang == "FR" %}
    <div id="FrenchCustomFields">
    <p>French stuff </p>
    </div>
    {% endif %}
    {% if custom_lang == "ES" %}
    <div id="SpanishCustomFields">
    <p>Spanish stuff </p>
    </div>
    {% endif %}
    </div>
    <!-- .fc_inner -->
    </fieldset>
    <!-- #fc_custom_fields -->
  • Great, thanks.
Sign In or Register to comment.