Polymer 1.x:<paper-toggle-botton> VALUE不会关闭

时间:2015-11-07 09:46:40

标签: polymer polymer-1.0 paper-elements

  

我无法使用<paper-toggle-button><iron-form>.serialize()元素的切换为“off”值。虽然视觉渲染显示以切换到“关闭”位置。

我做错了什么?

Here is a link to the JSBin demo

  1. 单击演示中的切换按钮以查看其值。
  2. 每个按钮的值都设置为“off”。
  3. 第一次点击每个按钮会将值设置为“on。”
  4. 在切换“开启”后,该值永远不会切换回“关闭”。
  5. 每个切换按钮的可视化渲染似乎按预期工作。
  6. http://jsbin.com/ruzuwaqiyi/edit?html,output
    <!DOCTYPE html>
    <html>  
    <head>
      <meta charset="utf-8">
      <title>Polymer Bin</title>
      <base href="http://element-party.xyz/">
      <script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
      <link rel="import" href="all-elements.html">
    </head>
    <body class="fullbleed layout vertical">
    <x-element></x-element>
    <dom-module id="x-element">
      <template>
        <style>
          paper-toggle-button {
            display: block;
            margin-bottom: 40px;
          }
        </style>
        <form is="iron-form" id="form">
          <p>Click each button to view the values.</p>
          <paper-toggle-button name="foo" on-change="handle">foo</paper-toggle-button>
          <paper-toggle-button name="bar" on-change="handle">bar</paper-toggle-button>
          <paper-toggle-button name="baz" on-change="handle">baz</paper-toggle-button>
          <paper-toggle-button name="bat" on-change="handle">bat</paper-toggle-button>
          <p>See how the values never toggle back to "off?"
        </form>
      </template>
      <script>
        (function(){
          Polymer({
            is: 'x-element',
            handle: function() {
              alert(JSON.stringify(this.$.form.serialize()));
            }
          });
        })();
      </script>
    </dom-module>
    </body>
    </html>
    

1 个答案:

答案 0 :(得分:0)

我想我只会使用<paper-checkbox>元素。 JSBin

http://jsbin.com/dewixacagu/edit?html,output
<!DOCTYPE html>
<html>  
<head>
  <meta charset="utf-8">
  <title>Polymer Bin</title>
  <base href="http://element-party.xyz/">
  <script src="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="all-elements.html">
</head>
<body class="fullbleed layout vertical">
<x-element></x-element>
<dom-module id="x-element">
  <template>
    <style>
      paper-checkbox {
        display: block;
        margin-bottom: 40px;
      }
    </style>
    <form is="iron-form" id="form">
      <p>Click each button to view the values.</p>
      <paper-checkbox name="foo" on-change="handle">foo</paper-checkbox>
      <paper-checkbox name="bar" on-change="handle">bar</paper-checkbox>
      <paper-checkbox name="baz" on-change="handle">baz</paper-checkbox>
      <paper-checkbox name="qux" on-change="handle">qux</paper-checkbox>
      <p>See how the values toggle back to "off" now?</p>
    </form>
  </template>
  <script>
    (function(){
      Polymer({
        is: 'x-element',
        handle: function() {
          alert(JSON.stringify(this.$.form.serialize()));
        }
      });
    })();
  </script>
</dom-module>
</body>
</html>