<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/** @var \Magento\Tax\Block\Adminhtml\Rate\Form $form */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
?>
<?php if ($form): ?>
    <?= $form->toHtml() ?>
    <?php $scriptString = <<<script
    require([
        "jquery",
        "mage/mage"
    ], function($){

        $('#{$block->escapeJs($form->getForm()->getId())}').mage('form').mage('validation');

        $(document).ready(function () {
            'use strict';

            $('.field-zip_from').addClass('ignore-validate');
            $('.field-zip_to').addClass('ignore-validate');

            $('#zip_is_range').on('change.zipRange', function(){

                var elem = $(this),
                    zipFrom =$('.field-zip_from'),
                    zipTo =$('.field-zip_to'),
                    zipCode =$('.field-tax_postcode');

                if (elem.is(':checked')) {
                    zipCode.addClass('hidden').addClass('ignore-validate');
                    zipFrom.removeClass('hidden').removeClass('ignore-validate');
                    zipTo.removeClass('hidden').removeClass('ignore-validate');

                } else {
                    zipCode.removeClass('hidden').removeClass('ignore-validate');
                    zipFrom.addClass('hidden').addClass('ignore-validate');
                    zipTo.addClass('hidden').addClass('ignore-validate');
                }

            });
        });

    });
script;
    ?>
    <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
<?php endif; ?>
