当我提交带有document.getElementById("form").submit();
的这个Polymer表单时,firstName和lastName都包含在POST数据中,但是paper-dropdown-menu中的title-value没有。缺少什么?
<form is="iron-form" id="form" method="post" action="/edit">
<paper-dropdown-menu name="title" label="Title">
<paper-menu class="dropdown-content">
<template is="dom-repeat" items="{{titles}}" as="title">
<paper-item value="{{item.id}}">{{title.name}}</paper-item>
</template>
</paper-menu>
</paper-dropdown-menu>
<paper-input name="firstName" label="First name"></paper-input>
<paper-input name="lastName" label="Last name"></paper-input>
<paper-button raised onclick="submitForm()">Save</paper-button>
</form>
修改
这是我完整的工作实例,非常感谢@Brandon的回答:
<form is="iron-form" id="form" method="post" action="/api/edit">
<paper-dropdown-menu label="Title" selected-item="{{selectedItem}}" selected-item-label="{{selected}}">
<paper-menu class="dropdown-content">
<template is="dom-repeat" items="{{titles}}" as="title">
<paper-item value="[[title.id]]">[[title.name]]</paper-item>
</template>
</paper-menu>
</paper-dropdown-menu>
<input is="iron-input" name="title" type="hidden" value$="[[selectedItem.value]]">
<paper-input name="firstName" label="First name"></paper-input>
<paper-input name="lastName" label="Last name"></paper-input>
<paper-button raised onclick="document.getElementById('form').submit()">Save</paper-button>
</form>
答案 0 :(得分:7)
这可以解决您的问题。创建隐藏的输入元素,并将所选项目分配给隐藏元素的值。这为您提供了铁输入验证器的额外好处,可以为将来的表格进行多选。
<form is="iron-form" id="form" method="post" action="/edit">
<paper-dropdown-menu label="Title" selected-item-label="{{selected}}">
<paper-menu class="dropdown-content">
<template is="dom-repeat" items="{{titles}}" as="title">
<paper-item>{{title.name}}</paper-item>
</template>
</paper-menu>
</paper-dropdown-menu>
<input is="iron-input" name="title" type="hidden" value$="[[selected]]">
<paper-input name="firstName" label="First name"></paper-input>
<paper-input name="lastName" label="Last name"></paper-input>
<paper-button raised onclick="submitForm()">Save</paper-button>
</form>