Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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">
  <h1>Ограничиваем сектор поиска в подсказках по ФИАС</h1>
  <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="#msk" data-switch="msk">Конкретный регион (Москва)</a></li>
    <li><a href="#nsk" data-switch="nsk">Конкретный город (Новосибирск)</a></li>
    <li><a href="#kladr" data-switch="kladr">Ограничение по коду КЛАДР (Тольятти)</a></li>
    <li><a href="#fias" data-switch="fias">Ограничение по коду ФИАС (Краснодарский край)</a></li>
    <li><a href="#fd" data-switch="fd">Федеральный округ (ЮФО)</a></li>
  </ul>
</section>

              
            
!

CSS

              
                input {
  font-size: 16px;
  padding: 4px;
}
#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 msk() {
  $("#label").text("Конкретный регион (Москва)");
  $("#address").suggestions({
    token: TOKEN,
    type: "FIAS",
    constraints: {
      locations: { region: "Москва" }
    },
    restrict_value: true
  });
}

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

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

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

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

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

none();
              
            
!
999px

Console