我已经在我的表单中实现了无线电组按钮,并且我希望将所选值发布到php来处理搜索请求,但是我注意到这些按钮本身将其值推送到了,即' selectedButton =上'对于php文档,我希望他们发布自己的名字,即" selectedButton = selectedButton'我已设法通过将其值设置为名称来实现此目的,但这会导致所有项目都可选择
<paper-radio-group>
<form id="searchForm" is="iron-form" method="POST" action="search.php">
<paper-radio-button name="Toyota">Toyota</paper-radio-button> <br>
<paper-radio-button name="Mitsubishi">Mitsubishi</paper-radio-button> <br>
<paper-radio-button name="Subaru">Subaru</paper-radio-button> <br>
<paper-radio-button name="Nissan">Nissan</paper-radio-button> <br>
<paper-radio-button name="BMW">BMW</paper-radio-button> <br>
</form>
</paper-radio-group>
<paper-button raised type="submit" on-click="_submit">Search</paper-button>
</paper-card>
脚本
<script>
'use strict';
(function() {
Polymer({
is: 'search-form',
properties: {
status: String
},
listeners: {
'iron-form-submit': '_formSubmit',
'iron-form-response': '_formResponse',
'iron-form-error': '_formError'
},
_submit: function(event) {
this.$.searchForm.submit();
},
_formSubmit: function(event) {
this.status = 'Submitted...'
console.log('The form has been submited.', event);
},
_formResponse: function(event) {
this.status = 'Completed ' + event.detail.xhr.response;
console.log('Form responded:', event.detail.xhr.response);
},
_formError: function(event) {
this.status = 'Errored: ' + event.detail
console.log('Form error:', event.detail);
},
attached: function() {
this.status = ' ';
}
created: function () {
this.selection = "medium"
},
selectionChanged: function () {
console.log(this.selection);
}
});
})();
</script>
答案 0 :(得分:2)
注意到我无法直接选择像原生单选按钮那样的值 所以我改变了代码提交汽车:模型,并在PHP中找到其余的
<paper-radio-group selected="{{brand}}">
<paper-radio-button name="toyota">Toyota</paper-radio-button>
<paper-radio-button name="bmw">BMW</paper-radio-button>
<paper-radio-button name="subaru">Subaru</paper-radio-button>
<paper-radio-button name="mitsubishi">Mitsubishi</paper-radio-button>
<paper-radio-button name="nissan">Nissan</paper-radio-button>
<paper-radio-button name="mazda">Mazda</paper-radio-button>
<paper-radio-button name="chrysler">Chrysler</paper-radio-button>
</paper-radio-group>
<paper-button raised type="submit" on-click="_submit">Search</paper-button>
脚本
<script>
'use strict';
(function() {
Polymer({
is: 'search-form',
properties: {
brand: {
type: String,
value: 'toyota'
}
},
listeners: {
'iron-form-presubmit': '_formPresubmit',
'iron-form-submit': '_formSubmit',
'iron-form-response': '_formResponse',
'iron-form-error': '_formError'
},
_submit: function(event) {
this.$['the-form'].submit();
},
_formPresubmit: function() {
this.$['the-form'].request.params = { brand: this.brand };
},
_formSubmit: function(event) {
}
});
})();
</script>
希望这会有所帮助