Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section class="container">
  <h3>
    <a class="logo" href="https://dadata.ru/suggestions/usage/address/" target="_blank">DaData.ru</a> •
    Ограничить сектор поиска в подсказках по адресу
  </h3>
  <p><span id="label">Без ограничений</span>:</p>
  <input id="address" name="address" type="text" />
  <p>Выберите вариант:</p>
  <ul id="switcher">
    <li><a href="#none" data-switch="none">Без ограничений</a></li>
    <li><a href="#foreign" data-switch="foreign">Конкретная страна (Казахстан)</a></li>
    <li><a href="#msk" data-switch="msk">Конкретный регион (Москва)</a></li>
    <li><a href="#nsk" data-switch="nsk">Конкретный город (Новосибирск)</a></li>
    <li><a href="#sam" data-switch="sam">Конкретный город (Самара)</a></li>
    <li><a href="#kladr" data-switch="kladr">Ограничение по коду КЛАДР (Тольятти)</a></li>
    <li><a href="#fias" data-switch="fias">Ограничение по коду ФИАС (Краснодарский край)</a></li>
    <li><a href="#regions" data-switch="regions">Несколько регионов (Москва и Московская область)</a></li>
    <li><a href="#fd" data-switch="fd">Федеральный округ (ЮФО)</a></li>
    <li><a href="#iso" data-switch="iso">По ISO-коду страны и региона (Германия, Гессен)</a></li>
     <li><a href="#isoreg" data-switch="isoreg">По названию страны и региона (Беларусь, Брестская область)</a></li>
  </ul>
</section>

              
            
!

CSS

              
                body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 20px;
  padding: 0.25rem 1.5rem;
}

input {
  font-size: 1.25rem;
  padding: 0.5rem;
}

p {
  font-size: 1.25rem;
}

pre {
  font-size: 1rem;
}
code {
  font-family: ui-monospace, "SFMono-Regular", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 1rem;
}

a.logo {
  color: #f43e3e;
  text-decoration: none;
  border-bottom: 1px solid rgba(244, 62, 62, 1);
}
a.logo:hover {
  border-bottom: none;
}

#switcher a {
  text-decoration: none;
  border-bottom: 1px dotted blue;
}
#switcher a:hover {
  border-bottom: none;
}
#switcher li {
  line-height: 1.5
}
              
            
!

JS

              
                // Замените на свой API-ключ
var TOKEN = "7fd18aaabd7d53ffa4846e4521c1f736c13490eb";

function none() {
  $("#label").text("Без ограничений");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
  });
}

function foreign() {
  $("#label").text("Конкретная страна (Казахстан)");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
    constraints: {
      // ISO-код страны
      // Список ISO-кодов: https://ru.wikipedia.org/wiki/ISO_3166-1
      locations: { country_iso_code: "KZ" },
    }
  });
}

function msk() {
  $("#label").text("Конкретный регион (Москва)");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
    constraints: {
      // ограничиваем поиск Москвой
      locations: { region: "Москва" },
    },
    // в списке подсказок не показываем область
    restrict_value: true
  });
}

function nsk() {
  $("#label").text("Конкретный город (Новосбирск)");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
    constraints: {
      // ограничиваем поиск Новосибирском
      locations: {
        region: "Новосибирская",
        city: "Новосибирск"
      },
    },
    // в списке подсказок не показываем область и город
    restrict_value: true
  });
}

function sam() {
  $("#label").text("Конкретный город (Самара)");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
    constraints: {
      locations: {
        kladr_id: "6300000100000"
      }
    },
    // в списке подсказок не показываем область и город
    restrict_value: true
  });
}

function kladr() {
  $("#label").text("Ограничение по коду КЛАДР (Тольятти)");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
    constraints: {
      // ограничиваем поиск городом Тольятти по коду КЛАДР
      locations: { kladr_id: "63000007" },
    },
    // в списке подсказок не показываем область и город
    restrict_value: true
  });
}

function fias() {
  $("#label").text("Ограничение по коду ФИАС (Краснодарский край)");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
    constraints: {
      // ограничиваем поиск Краснодарским краем по коду ФИАС
      locations: { 
        region_fias_id: "d00e1013-16bd-4c09-b3d5-3cb09fc54bd8" 
      },
    },
    // в списке подсказок не показываем регион
    restrict_value: true
  });
}

function regions() {
  $("#label").text("Несколько регионов (Москва и Московская область)");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
    constraints: [
      // Москва
      {
        locations: { region: 'Москва' },
      },
      // Московская область
      {
        locations: { kladr_id: '50' },
      }
    ]
  });
}

function fd() {
  $("#label").text("Федеральный округ (ЮФО)");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
    constraints: {
        // несколько ограничений по ИЛИ
        locations: [
            {"region": "адыгея"},
            {"region": "астраханская"},
            {"region": "волгоградская"},
            {"region": "калмыкия"},
            {"region": "краснодарский"},
            {"region": "ростовская"}
        ]
    }
  });
}

function iso() {
  $("#label").text("По ISO-коду страны и региона (Германия, Гессен)");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
    constraints: {
      locations: {
        country_iso_code: "DE",
        region_iso_code: "DE-HE"
      },
    }
  });
}

function isoreg() {
  $("#label").text("По названию страны и региона (Беларусь, Брестская область)");
  $("#address").suggestions({
    token: TOKEN,
    type: "ADDRESS",
    constraints: {
      locations: {
        country: "Беларусь",
        region: "Брестская",
      },
    }
  });
}

$("#switcher a").click(function(e) {
  e.preventDefault();
  $("#address").val("");
  var fnName = $(this).data("switch");
  window[fnName]();
});

none();
              
            
!
999px

Console