CMS Development

FurqanAli
Teilnehmer/-in

How to get data for the next and previous index in the for loop in hubl for setting conditions?

lösung

Hi there,

I'm trying to set conditions in Hubl under for loop for the repeated fields.  You can see my code below under the script tag where I'm using different values:

<script>
function showVal(newVal){
if(newVal <= {{ module.free_slab_limit }}){
jQuery(".pricing-columns__item.featured.alternated p.pricing-columns__price").text("{{free_text.freeText}}");
jQuery(".workspace_members span").text(newVal);
}
{% for item in module.step_fields %}
else if( newVal>= {{item.step_value}} && (Here I need to use the condition for next and previous index)){
jQuery(".workspace_members span").text("{{ item.step_text }}");
}
{% endfor %}
else{
jQuery(".pricing-columns__item.featured.alternated p.pricing-columns__price").text("$" + (newVal*{{ module.per_user_cost }}));
jQuery(".workspace_members span").text(newVal);
}
}
</script>

Thanks for the help as well. 

0 Upvotes
1 Akzeptierte Lösung
MBERARD
Lösung
Stratege/Strategin | Elite Partner
Stratege/Strategin | Elite Partner

How to get data for the next and previous index in the for loop in hubl for setting conditions?

lösung

Hi @FurqanAli ,

is that something like so you want to perform?

<script>
    function showVal(newVal) {
        if (newVal <= {{ module.free_slab_limit }}) {
            jQuery(".pricing-columns__item.featured.alternated p.pricing-columns__price").text("{{ free_text.freeText }}");
            jQuery(".workspace_members span").text(newVal);
        }
        {% for item in module.step_fields %}
            {% if loop.first %}
                else if (newVal >= {{ item.step_value }} && ({{ module.step_fields[loop.index0 + 1].step_value }})) { // only next value
                    jQuery(".workspace_members span").text("{{ item.step_text }}");
                }
            {% elif loop.last %}
                else if (newVal >= {{ item.step_value }} && ({{ module.step_fields[loop.index0 - 1].step_value }})) { // only prev value
                    jQuery(".workspace_members span").text("{{ item.step_text }}");
                }
            {% else %}
                else if (newVal >= {{ item.step_value }} && ({{ module.step_fields[loop.index0 - 1].step_value }} && {{ module.step_fields[loop.index0 + 1].step_value }})) { // prev & next value
                    jQuery(".workspace_members span").text("{{ item.step_text }}");
                }
            {% endif %}
        {% endfor %}
        else {
            jQuery(".pricing-columns__item.featured.alternated p.pricing-columns__price").text("$" + (newVal * {{ module.per_user_cost }}));
            jQuery(".workspace_members span").text(newVal);
        }
    }
</script>

 

Kind regards,

 

Matthieu

matthieu.berard@markentive.com

Lösung in ursprünglichem Beitrag anzeigen

3 Antworten
MBERARD
Lösung
Stratege/Strategin | Elite Partner
Stratege/Strategin | Elite Partner

How to get data for the next and previous index in the for loop in hubl for setting conditions?

lösung

Hi @FurqanAli ,

is that something like so you want to perform?

<script>
    function showVal(newVal) {
        if (newVal <= {{ module.free_slab_limit }}) {
            jQuery(".pricing-columns__item.featured.alternated p.pricing-columns__price").text("{{ free_text.freeText }}");
            jQuery(".workspace_members span").text(newVal);
        }
        {% for item in module.step_fields %}
            {% if loop.first %}
                else if (newVal >= {{ item.step_value }} && ({{ module.step_fields[loop.index0 + 1].step_value }})) { // only next value
                    jQuery(".workspace_members span").text("{{ item.step_text }}");
                }
            {% elif loop.last %}
                else if (newVal >= {{ item.step_value }} && ({{ module.step_fields[loop.index0 - 1].step_value }})) { // only prev value
                    jQuery(".workspace_members span").text("{{ item.step_text }}");
                }
            {% else %}
                else if (newVal >= {{ item.step_value }} && ({{ module.step_fields[loop.index0 - 1].step_value }} && {{ module.step_fields[loop.index0 + 1].step_value }})) { // prev & next value
                    jQuery(".workspace_members span").text("{{ item.step_text }}");
                }
            {% endif %}
        {% endfor %}
        else {
            jQuery(".pricing-columns__item.featured.alternated p.pricing-columns__price").text("$" + (newVal * {{ module.per_user_cost }}));
            jQuery(".workspace_members span").text(newVal);
        }
    }
</script>

 

Kind regards,

 

Matthieu

matthieu.berard@markentive.com

FurqanAli
Teilnehmer/-in

How to get data for the next and previous index in the for loop in hubl for setting conditions?

lösung

Thanks for clarifying many things in your code related to indexes and setting conditions under the loop; this is something I was looking for. @MBERARD 

0 Upvotes
MBERARD
Stratege/Strategin | Elite Partner
Stratege/Strategin | Elite Partner

How to get data for the next and previous index in the for loop in hubl for setting conditions?

lösung

Happy to helped 😊

0 Upvotes