Conditions to hide VAT fields fail if there are no company fields

"Company" fields may or may not be rendered on this form, whereas "VAT" fields are always rendered and depend on the former ones to be shown (or hidden) with CSS.

This fixes an edge case where there are no "Company" fields rendered and "VAT" fields still wrongly appear, which was caused by the fact that `$('#field').val() != ''` is truthy when `$('#field').length` is zero (since `'' != undefined`).
This commit is contained in:
Tom Panier
2013-10-24 09:43:50 +02:00
parent 56693da6e0
commit 6d3640e895
+3 -3
View File
@@ -74,14 +74,14 @@
{literal}
function vat_number()
{
if ($('#company').val() != '')
if (($('#company').length) && ($('#company').val() != ''))
$('#vat_number_block').show();
else
$('#vat_number_block').hide();
}
function vat_number_invoice()
{
if ($('#company_invoice').val() != '')
if (($('#company_invoice').length) && ($('#company_invoice').val() != ''))
$('#vat_number_block_invoice').show();
else
$('#vat_number_block_invoice').hide();
@@ -405,4 +405,4 @@
</fieldset>
</form>
<div class="clear"></div>
</div>
</div>