Created
March 8, 2018 13:01
-
-
Save PepDevils/71590a9e9b1e016fad5d5d47a753d428 to your computer and use it in GitHub Desktop.
Plataforma OpenCart No template/layout do produto, esconder ou mostar Opções dependentes de um <select>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Plataforma OpenCart | |
| No template/layout do produto, esconder ou mostar Opções dependentes de um <select> | |
| //catalog/view/theme/custom_theme/template/product/product.tpl | |
| //line 120 a nossa referencia principal para encontrar o <select> | |
| <div id="product"> | |
| //line 126 - o <select> - acrescentar uma função onchange | |
| <select onchange="functionSelectAndToggle();" name="option[<?php echo $option['product_option_id']; ?>]" id="input-option<?php echo $option['product_option_id']; ?>" class="form-control"> | |
| //agora no fundo do documento e antes de <?php echo $footer; ?> | |
| //colocamos o codigo para a nossa função | |
| //line 715 | |
| <script> | |
| //rodar função quando a pagina inicia | |
| $(document).ready(function() { | |
| functionSelectAndToggle(); | |
| }); | |
| function functionSelectAndToggle(){ | |
| $("select").each(function(){ | |
| //inicializar para ter valor | |
| var value_opt = "value"; | |
| var idenz = "input-option"; | |
| if($(this).text().indexOf("Nome + Número (+15.00€)")){ | |
| var d = 750;//miliseconds | |
| value_opt = $(this).val(); | |
| var idboss = $(this).attr('id'); | |
| var total_idboss = "select#" + idboss; | |
| var selected = $(total_idboss).find(":selected").val(); | |
| var number_id = parseInt(idboss.replace(idenz, "")); | |
| var child1_id = idenz + (number_id-1); | |
| var total_child1_id = "input#" + child1_id; | |
| var child2_id = idenz + (number_id-2); | |
| var total_child2_id = "input#" + child2_id; | |
| //se o valor de value_opt for "undifine" então esconde as opções | |
| //se tiver valor então mostra | |
| if(value_opt){ | |
| console.log("yes"); | |
| $(total_child1_id).parent().slideDown(d); | |
| $(total_child2_id).parent().slideDown(d); | |
| //limpar imputs | |
| $(total_child1_id).val(''); | |
| $(total_child2_id).val(''); | |
| }else{ | |
| console.log("no"); | |
| $(total_child1_id).parent().slideUp(d); | |
| $(total_child2_id).parent().slideUp(d); | |
| //limpar imputs | |
| $(total_child1_id).val(''); | |
| $(total_child2_id).val(''); | |
| } | |
| } | |
| }); | |
| } | |
| </script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment