How to include Polymer paper-dropdown-menu in form submit

后端 未结 1 1496
-上瘾入骨i
-上瘾入骨i 2021-01-05 14:56

When I submit this Polymer form with document.getElementById(\"form\").submit(); firstName and lastName are included in the POST-data, but the title-value from

相关标签:
1条回答
  • 2021-01-05 15:08

    This may solve your problem. Create a hidden input element and assign the selected item to the hidden element's value. This gives you the added benefit of the iron-input validators for multi-select for future forms.

    <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>
    
    0 讨论(0)
提交回复
热议问题