index.html 5.28 KB
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
  <title>iron-form demo</title>

  <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
  <meta name="mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes">

  <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="../../paper-input/paper-input.html">
  <link rel="import" href="../../paper-button/paper-button.html">
  <link rel="import" href="../../paper-styles/demo-pages.html">
  <link rel="import" href="../../paper-checkbox/paper-checkbox.html">
  <link rel="import" href="../../paper-dropdown-menu/paper-dropdown-menu.html">
  <link rel="import" href="../../paper-menu/paper-menu.html">
  <link rel="import" href="../../paper-item/paper-item.html">
  <link rel="import" href="../iron-form.html">
  <link rel="import" href="simple-element.html">
</head>
<style>
  .wide {
    width: 474px;
  }
</style>
<body>
  <div class="horizontal-section-container">
    <div>
      <h4>method="get"</h4>
      <div class="horizontal-section">
        <form is="iron-form" id="formGet" method="get" action="/">
          <paper-input name="name" label="Name" required></paper-input>
          <paper-input name="animal" label="Favourite animal" required></paper-input>
          <br>

          <input type="checkbox" name="food" value="donuts" checked> I like donuts<br>
          <input type="checkbox" name="food" value="pizza" required> I like pizza<br>
          <paper-checkbox name="food" value="cheese" required>I like cheese</paper-checkbox><br>

          <paper-dropdown-menu label="Cars" name="cars" required>
            <paper-menu class="dropdown-content">
              <paper-item>Volvo</paper-item>
              <paper-item>Saab</paper-item>
              <paper-item>Fiat</paper-item>
              <paper-item>Audi</paper-item>
            </paper-menu>
          </paper-dropdown-menu>

          <p>
            Sample custom element, not required: <br>
            <simple-element name="custom-one"></simple-element>
          </p>

          <p>
            Sample custom element, required: (look, styling!)<br>
            <simple-element required name="custom-two"></simple-element><br>
          </p>

          <br><br>

          <paper-button raised
              onclick="submitHandler(event)">Submit</paper-button>
          <paper-button raised
              onclick="resetHandler(event)">Reset</paper-button>
        </form>
      </div>
    </div>

    <div>
      <h4>method="post"</h4>
      <div class="horizontal-section">
        <form is="iron-form" id="formPost" method="post" action="/">
          <paper-input name="name" label="Name" required></paper-input>
          <br>
          <p>Duplicate name <input name="name" required></p>

          <input type="radio" name="color" value="red" checked>Red<br>
          <input type="radio" name="color" value="blue" checked>Blue<br>
          <input type="radio" name="color" value="green">Green<br>
          <br>

          <label>Cars</label>
          <select name="cars">
            <option value="volvo">Volvo</option>
            <option value="saab">Saab</option>
            <option value="fiat">Fiat</option>
            <option value="audi">Audi</option>
          </select>

          <br><br>
          <label>Browsers</label>
          <input list="browsers" name="browsers" required>
            <datalist id="browsers">
              <option value="Internet Explorer">
              <option value="Firefox">
              <option value="Chrome">
              <option value="Opera">
              <option value="Safari">
            </datalist>
          <br><br>

          <label>Pick a number</label>
          <input type="range" name="number" min="1" max="100">

          <br><br><br>
          <paper-button raised
              onclick="submitHandler(event)">Submit</paper-button>
          <button type="submit">Native Submit</button>
          <button type="reset">Native Reset</button>
        </form>
      </div>
    </div>
  </div>
  <br><br>
  <div class="horizontal-section-container">
    <div>
      <h4>Submitted form data</h4>
      <div class="horizontal-section wide">
        <div id="output"></div>
      </div>
    </div>
  </div>

  <script>
    document.getElementById('formGet').addEventListener('iron-form-submit', display);
    document.getElementById('formPost').addEventListener('iron-form-submit', display);

    function display(event) {
      var output = document.getElementById('output');
      output.innerHTML = JSON.stringify(event.detail);
    }

    function submitHandler(event) {
      Polymer.dom(event).localTarget.parentElement.submit();
    }
    function resetHandler(event) {
      Polymer.dom(event).localTarget.parentElement.reset();
    }
  </script>
</body>

</html>