Skip to content

Commit 75ac5b9

Browse files
authored
Подсказки по адресу и email
1 parent 2122931 commit 75ac5b9

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

init.js

+27-21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@
1717
$field.parent().removeClass("co-input--empty_nested");
1818
}
1919

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+
2035
function clearParty() {
2136
clearField("client_juridical_address");
2237
clearField("client_inn");
@@ -34,16 +49,6 @@
3449
showField("client_kpp", party.kpp);
3550
showField("client_ogrn", party.ogrn);
3651
}
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-
}
4752

4853
function clearBank() {
4954
clearField("client_bik");
@@ -55,20 +60,21 @@
5560
showField("client_bik", bank.bic);
5661
showField("client_correspondent_account", bank.correspondent_account);
5762
}
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);
6771
}
6872

6973
$(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 });
7278
});
7379

7480
}(window.jQuery, window.DADATA_TOKEN))

0 commit comments

Comments
 (0)