|
17 | 17 | $field.parent().removeClass("co-input--empty_nested");
|
18 | 18 | }
|
19 | 19 |
|
| 20 | + function pass() {} |
| 21 | + |
| 22 | + function init(id, type, showFunc, clearFunc, options) { |
| 23 | + var plugin = $("#" + id).suggestions({ |
| 24 | + token: TOKEN, |
| 25 | + partner: PARTNER, |
| 26 | + type: type, |
| 27 | + onSelect: showFunc, |
| 28 | + onSelectNothing: clearFunc |
| 29 | + }).suggestions(); |
| 30 | + if (options) { |
| 31 | + plugin.setOptions(options); |
| 32 | + } |
| 33 | + } |
| 34 | + |
20 | 35 | function clearParty() {
|
21 | 36 | clearField("client_juridical_address");
|
22 | 37 | clearField("client_inn");
|
|
34 | 49 | showField("client_kpp", party.kpp);
|
35 | 50 | showField("client_ogrn", party.ogrn);
|
36 | 51 | }
|
37 |
| - |
38 |
| - function initParty() { |
39 |
| - $("#client_name").suggestions({ |
40 |
| - token: TOKEN, |
41 |
| - partner: PARTNER, |
42 |
| - type: "PARTY", |
43 |
| - onSelect: showParty, |
44 |
| - onSelectNothing: clearParty |
45 |
| - }); |
46 |
| - } |
47 | 52 |
|
48 | 53 | function clearBank() {
|
49 | 54 | clearField("client_bik");
|
|
55 | 60 | showField("client_bik", bank.bic);
|
56 | 61 | showField("client_correspondent_account", bank.correspondent_account);
|
57 | 62 | }
|
58 |
| - |
59 |
| - function initBank() { |
60 |
| - $("#client_bank_name").suggestions({ |
61 |
| - token: TOKEN, |
62 |
| - partner: PARTNER, |
63 |
| - type: "BANK", |
64 |
| - onSelect: showBank, |
65 |
| - onSelectNothing: clearBank |
66 |
| - }); |
| 63 | + |
| 64 | + function clearAddress() { |
| 65 | + clearField("shipping_address_zip"); |
| 66 | + } |
| 67 | + |
| 68 | + function showAddress(suggestion) { |
| 69 | + var address = suggestion.data; |
| 70 | + showField("shipping_address_zip", address.postal_code); |
67 | 71 | }
|
68 | 72 |
|
69 | 73 | $(function () {
|
70 |
| - initParty(); |
71 |
| - initBank(); |
| 74 | + init("client_name", "PARTY", showParty, clearParty); |
| 75 | + init("client_bank_name", "BANK", showBank, clearBank); |
| 76 | + init("shipping_address_address", "ADDRESS", showAddress, clearAddress); |
| 77 | + init("client_email", "EMAIL", pass, pass, { suggest_local: false }); |
72 | 78 | });
|
73 | 79 |
|
74 | 80 | }(window.jQuery, window.DADATA_TOKEN))
|
0 commit comments