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>Введите адрес, чтобы продолжить:<br>
    <input id="address" name="address" type="text" />
   </p>
  <p id="message"></p>
  <button id="continue" disabled>Продолжить</button>
</section>

              
            
!

CSS

              
                input {
  font-size: 16px;
  padding: 4px;
}
              
            
!

JS

              
                var $address = $("#address");
var $message = $("#message");
var $continue = $("#continue");
var selectedAddress;

function checkAddress(address) {
  var isGood = true;
  var message = "";
  if (address.house === null) {
    isGood = false;
    message = "не указан дом";
  } else if (address.fias_level !== "8") {
    isGood = false;
    message = "указан дом, которого нет в ФИАС";
  }
  return {
    isGood: isGood,
    message: message
  };
}

function selectAddress(suggestion) {
  console.log(suggestion);
  var address = suggestion.data;
  var checkResult = checkAddress(address);
  if (checkResult.isGood) {
    $message.text("Отлично, этот адрес подходит!");
    $continue.prop("disabled", false);
  } else {
    $message.text("Адрес не подходит: " + checkResult.message);
    $continue.prop("disabled", true);
  }
  selectedAddress = address;
}

function selectNone() {
  selectedAddress = null;
  $message.text("Вы не ввели адрес");
  $continue.prop("disabled", true);
}

$address.suggestions({
  serviceUrl: "https://suggestions.dadata.ru/suggestions/api/4_1/rs",
  token: "5ef98f5781a106962077fb18109095f9f11ebac1",
  type: "ADDRESS",
  onSelect: selectAddress,
  onSelectNothing: selectNone
});
              
            
!
999px

Console