{% if samepage %}
    {% if value is null %}
        {% set value = "" %}
    {% endif %}
    <script>
        jQuery(document).ready(function(){

                {% if type == "slider" %}

                jQuery(document).on('change', '#tsform-field-{{ fieldid }}-{{ formgroupindex }}', function (e) {

                    var value = jQuery('#tsform-field-{{ fieldid }}-{{ formgroupindex }}').val();

                    {% if range %}
                        if(value >= {{ range_min }} && value <= {{ range_max }} ) {
                            jQuery('#{{ randid }}').removeClass('d-none').addClass('d-block');
                        } else {
                            jQuery('#{{ randid }}').removeClass('d-block').addClass('d-none');
                        }
                    {% else %}
                        if(value == '{{ value }}') {
                            jQuery('#{{ randid }}').removeClass('d-none').addClass('d-block');
                        } else {
                            jQuery('#{{ randid }}').removeClass('d-block').addClass('d-none');
                        }
                    {% endif %}
                });
            
                {% elseif type == "select" or type == "input" or type == "textarea" %}
                    jQuery(document).on('change', '#tsform-field-{{ fieldid }}-{{ formgroupindex }}', function (e) {

                        var value = jQuery('#tsform-field-{{ fieldid }}-{{ formgroupindex }}').val();

                        if(jQuery.isArray(value)) {

                            var found = false;
                            for(var i = 0; i < value.length; i++) {
                                if(value[i] == '{{ value }}') {
                                    jQuery('#{{ randid }}').removeClass('d-none').addClass('d-block');
                                    found = true;
                                } else {
                                    if(!found) {
                                        jQuery('#{{ randid }}').removeClass('d-block').addClass('d-none');
                                    }
                                }
                            }

                        } else {
                            if(value == '{{ value }}') {
                                jQuery('#{{ randid }}').removeClass('d-none').addClass('d-block');
                            } else {
                                jQuery('#{{ randid }}').removeClass('d-block').addClass('d-none');
                            }
                        }
                    });
                {% elseif type == "radio" %} 

                    jQuery(document).on('click', "input[name='tsform-field-{{ fieldid }}-{{ formgroupindex }}']", function (e) {
                        var value = jQuery("input[name='tsform-field-{{ fieldid }}-{{ formgroupindex }}']:checked").val();
                        if(value == '{{ value }}') {
                            jQuery('#{{ randid }}').removeClass('d-none').addClass('d-block');
                        } else {
                            jQuery('#{{ randid }}').removeClass('d-block').addClass('d-none');
                        }
                    });

                {% elseif type == "checkbox" %}
                    jQuery(document).on('click', "#tsform-field-{{ fieldid }}-{{ formgroupindex }}", function(e) {
                        if(jQuery(this).prop('checked') && jQuery(this).val() == '{{ value }}') {
                            jQuery('#{{ randid }}').removeClass('d-none').addClass('d-block');
                        } else {
                            jQuery('#{{ randid }}').removeClass('d-block').addClass('d-none');
                        }
                    });

                {% elseif type == "scale" %} 
                
                    jQuery(document).on('click', "#ts-forms-scale-{{ fieldid }} tr.scaleTrData[data-row='{{ row }}'] input", function(e) {
                        if(jQuery(this).prop('checked') && jQuery(this).val() == '{{ value }}') {
                            jQuery('#{{ randid }}').removeClass('d-none').addClass('d-block');
                        } else {
                            jQuery('#{{ randid }}').removeClass('d-block').addClass('d-none');
                        }
                    });

                {% elseif type == "matrix" %} 

                    jQuery(document).on('click', "#ts-forms-matrix-{{ fieldid }} tbody tr[data-row='{{ row }}'] input", function(e) {
                        if(jQuery(this).prop('checked') && jQuery(this).val() == '{{ value }}') {
                            jQuery('#{{ randid }}').removeClass('d-none').addClass('d-block');
                        } else {
                            jQuery('#{{ randid }}').removeClass('d-block').addClass('d-none');
                        }
                    });

                {% endif %}
        });
    </script>
{% endif %}
<div id="{{ randid }}" class="ts-form-{{formid}}-conditional-content {% if show %}d-block{% else %}d-none{% endif %}">
    {{ htmlcontent|raw }}
</div>