XF 2.0 Conditional Registration Field

V3NTUS

Well-known member
I would like to set an optional Registration Field to appear in the registration page only if a user selects a determined Country from my custom Country Dropdown list.

For instance, this is the Country:

Code:
<option value="88">My Country</option>

but the problem is, when a user selects an option from the dropdown, the html isn't updated at all, so I can't grab this info in order to call something via javascript like an onclick function which would make the optional field appear.

So here's my question, how can I make a custom user field dependant on another custom field? Even a solution like the following:

Code:
<div class="optionalfield" style="display:hidden">......</div>
<xf:if="{$selectedfieldId.Value == 88}">
<style>
.optionalfield {display:initial}
</style>
</xf:if>

would be good, if working. (the one above is of course just a non-working example)

Thanks!
 
I found a solution by myself by adding this in
custom_fields_macros
in a proper position
:

Code:
<script>
$('select.fieldId').change(function(){
    if ($(this).val() == 88) {
    $('[data-field="conditionalfield"]').addClass('triggershown');
    }
}).trigger('change');
</script>
<style>
.formRow--input.triggershown {
    display: table;
}
[data-field="conditionalfield"] {
    display: none;
}
</style>

Hopefully it'll help someone else out there.
 
Top Bottom