Help us understand the problem. What is going on with this article?

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

More than 1 year has passed since last update.

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 %}

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした