2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

EC-CUBE4で郵便番号にTABでフォーカス移動すると番地が消える

Last updated at Posted at 2019-08-14

EC-CUBE4の問題では無く、yubingango.jsに起因する問題。
例えば管理画面で会員情報を開いて、TABキーで郵便番号にフォーカス移すと、入力済の住所情報が消えてしまう。

対応

yubingango.jsがkeyupイベントで住所検索してしまうのが原因なので、yubingango.jsではなくAjaxZip3互換モジュールを使う。

管理画面の会員情報ページの場合、src/Eccube/Resource/template/admin/Customer/edit.twig を app/template/admin/Customer/edit.twig としてコピーして、コピーした方を編集する。

以下の部分を、

app/template/admin/Customer/edit.twig
{% block javascript %}
    <script src="//yubinbango.github.io/yubinbango/yubinbango.js" charset="UTF-8"></script>
{% endblock javascript %}

↓に差し替える。

app/template/admin/Customer/edit.twig
{% block javascript %}
    <script src="//yubinbango.github.io/ajaxzip3/ajaxzip3.js" charset="UTF-8"></script>
    <script>
        $(function() {
            $('.h-adr').each(function() {
                var $postal = $(this).find('.p-postal-code'),
                    $region = $(this).find('.p-region-id'),
                    $locality = $(this).find('.p-locality'),
                    $extended = $(this).find('.p-extended-address'),
                    $street = $('<input type="hidden">');

                $postal
                    .after($street)
                    .on('focus', function() {
                        $postal.data('lastvalue', $postal.val());
                    })
                    .on('keyup', function() {
                        if ($postal.data('lastvalue') != $postal.val()) {
                            $postal.data('lastvalue', $postal.val());
                            AjaxZip3.zip2addr($postal[0], '', $region[0], $locality[0], $street[0], $extended[0]);
                        }
                    });

                Object.defineProperty($street[0], 'value', {
                    get : function(){},
                    set : function(val){
                        if (val) {
                            $locality.val($locality.val() + val);
                        }
                    }
                })
            });
        });
    </script>
{% endblock javascript %}

もっと綺麗な方法がある気がする。

2
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?