From aab7538d25aebf0bd48c7be5420bd5a600ea8e6a Mon Sep 17 00:00:00 2001 From: Anton Zhiyanov Date: Wed, 8 Nov 2017 18:00:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=20=D0=B3=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=B4=D1=83=20=D0=B8=20=D0=BF=D0=BE=D0=B4=D1=81=D0=BA?= =?UTF-8?q?=D0=B0=D0=B7=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=A4=D0=98=D0=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - При смене «населённого пункта» на поле «адрес» накладываются соответствующие ограничения - Для физлиц работают подсказки по ФИО, для юрлиц — по организациям --- init.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/init.js b/init.js index e6aec46..8d7956a 100644 --- a/init.js +++ b/init.js @@ -70,11 +70,61 @@ showField("shipping_address_zip", address.postal_code); } + function listenCityChange() { + var $cityKladr = $("#shipping_address_full_locality_name"); + $cityKladr.on("change", onCityChange); + // initial check on page load + onCityChange(); + } + + function onCityChange() { + var kladrSelector = "[name='shipping_address[kladr_json]']"; + var kladr_id = null; + try { + var kladr = JSON.parse($(kladrSelector).val()); + kladr_id = kladr.kladr_code || kladr.code; + } catch (e) { + // do nothing + } + enforceCity(kladr_id); + } + + function enforceCity(kladr_id) { + clearField("shipping_address_address"); + clearField("shipping_address_zip"); + var sgt = $("#shipping_address_address").suggestions(); + if (kladr_id) { + setLocations(sgt, kladr_id); + } else { + clearLocations(sgt); + } + } + + function setLocations(sgt, kladr_id) { + sgt.setOptions({ + constraints: { + locations: { kladr_id: kladr_id } + }, + restrict_value: true + }); + } + + function clearLocations(sgt) { + sgt.setOptions({ + constraints: { + locations: null + }, + restrict_value: false + }); + } + $(function () { - init("client_name", "PARTY", showParty, clearParty); + init("tabs-organization #client_name", "PARTY", showParty, clearParty); + init("tabs-person #client_name", "NAME", pass, pass); init("client_bank_name", "BANK", showBank, clearBank); init("shipping_address_address", "ADDRESS", showAddress, clearAddress); + listenCityChange(); init("client_email", "EMAIL", pass, pass, { suggest_local: false }); }); - + }(window.jQuery, window.DADATA_TOKEN))