diff --git a/examples/js/all.js b/examples/js/all.js index 54b1ac2..5c50669 100644 --- a/examples/js/all.js +++ b/examples/js/all.js @@ -133,12 +133,22 @@ $(function () { $tooltip.hide(); }, check: function (obj) { + var $input = $(this); + if (obj) { - setLabel($(this), obj.type); + setLabel($input, obj.type); $tooltip.hide(); } else { - showError($(this), 'Введено неверно'); + showError($input, 'Введено неверно'); + } + }, + checkBefore: function () { + var $input = $(this); + + if (!$.trim($input.val())) { + $tooltip.hide(); + return false; } } }); @@ -247,6 +257,16 @@ $(function () { log(obj); addressUpdate(); mapUpdate(); + }, + checkBefore: function () { + var $input = $(this); + + if (!$.trim($input.val())) { + log(null); + addressUpdate(); + mapUpdate(); + return false; + } } }); @@ -288,26 +308,18 @@ $(function () { function mapUpdate() { var zoom = 4; - var address = $.kladr.getAddress($container.find('.js-form-address'), function (objs) { - var result = '', - name = '', - type = ''; + var address = $.kladr.getAddress('.js-form-address', function (objs) { + var result = ''; - for (var i in objs) { - if (objs.hasOwnProperty(i)) { - if ($.type(objs[i]) === 'object') { - name = objs[i].name; - type = ' ' + objs[i].type; - } - else { - name = objs[i]; - type = ''; - } + $.each(objs, function (i, obj) { + var name = '', + type = ''; - if (result) result += ', '; - result += type + name; + if ($.type(obj) === 'object') { + name = obj.name; + type = ' ' + obj.type; - switch (objs[i].contentType) { + switch (obj.contentType) { case $.kladr.type.region: zoom = 4; break; @@ -329,7 +341,13 @@ $(function () { break; } } - } + else { + name = obj; + } + + if (result) result += ', '; + result += type + name; + }); return result; }); diff --git a/examples/js/form.js b/examples/js/form.js index b8ab8e8..944b9e7 100644 --- a/examples/js/form.js +++ b/examples/js/form.js @@ -16,12 +16,22 @@ $(function () { $tooltip.hide(); }, check: function (obj) { + var $input = $(this); + if (obj) { - setLabel($(this), obj.type); + setLabel($input, obj.type); $tooltip.hide(); } else { - showError($(this), 'Введено неверно'); + showError($input, 'Введено неверно'); + } + }, + checkBefore: function () { + var $input = $(this); + + if (!$.trim($input.val())) { + $tooltip.hide(); + return false; } } }); diff --git a/examples/js/form_with_map.js b/examples/js/form_with_map.js index 0aa43d0..396c0ac 100644 --- a/examples/js/form_with_map.js +++ b/examples/js/form_with_map.js @@ -58,6 +58,16 @@ $(function () { log(obj); addressUpdate(); mapUpdate(); + }, + checkBefore: function () { + var $input = $(this); + + if (!$.trim($input.val())) { + log(null); + addressUpdate(); + mapUpdate(); + return false; + } } }); @@ -100,25 +110,17 @@ $(function () { var zoom = 4; var address = $.kladr.getAddress('.js-form-address', function (objs) { - var result = '', - name = '', - type = ''; - - for (var i in objs) { - if (objs.hasOwnProperty(i)) { - if ($.type(objs[i]) === 'object') { - name = objs[i].name; - type = ' ' + objs[i].type; - } - else { - name = objs[i]; - type = ''; - } + var result = ''; + + $.each(objs, function (i, obj) { + var name = '', + type = ''; - if (result) result += ', '; - result += type + name; + if ($.type(obj) === 'object') { + name = obj.name; + type = ' ' + obj.type; - switch (objs[i].contentType) { + switch (obj.contentType) { case $.kladr.type.region: zoom = 4; break; @@ -140,7 +142,13 @@ $(function () { break; } } - } + else { + name = obj; + } + + if (result) result += ', '; + result += type + name; + }); return result; });