简体   繁体   English

Select2在表单POST之后获得多项选择

[英]Select2 getting multiple selections after form POST

I have this select2 multi-selection dropdown that works fine on the client side but only posts the last selection users make: 我有这个select2多选下拉列表,该下拉列表在客户端可以正常运行,但仅发布用户所做的最后一次选择:

<select class="searchable-dropdown form-control form-control-md" name="payment_methods" id="payment-methods-send" multiple="multiple">
 <%= options_for_select( (::Transaction::SEND_METHODS).collect{ |m| [t(m[:name]), m[:name].parameterize ]}, selected: params[:payment_method] ) %>
</select>

It generates the following markup: 它生成以下标记:

<select class="searchable-dropdown form-control form-control-md" name="payment_methods" id="payment-methods-receive" multiple="multiple">
 <option value="coupons">Coupons</option>
 <option value="paypal">Paypal</option>
 <option value="skrill">Skrill</option>
 <option value="revolut">Revolut</option>
 <option value="zelle">Zelle</option>
 <option value="transferwise">Transferwise</option>
 <option value="swift-bank-transfer">SWIFT bank transfer</option>
 <option value="european-bank-transfer">European bank transfer</option>
 <option value="us-bank-transfer">US bank transfer</option>
 <option value="uk-bank-transfer">UK bank transfer</option>
 <option value="check">Check</option>
</select>

I've used this to initialize the control: 我用它来初始化控件:

$( ".searchable-dropdown" ).select2({ theme: "bootstrap" });

After making several selections and sending the form, I am getting this within params: 在做出几次选择并发送表格后,我将在参数中得到这个信息:

"payment_methods":"paypal"

Paypal was indeed selected (last) but so were a bunch of other selections. Paypal确实被选中(最后),但还有许多其他选择。

Was it not supposed to send them comma-separated or something? 难道不应该用逗号分隔它们吗? Am I doing something wrong? 难道我做错了什么?

Nevermind, looks like I wasn't asking Google the right question... 没关系,看来我不是在问Google正确的问题...

Multiple select box is not working in rails 多重选择框在导轨中不起作用

You need to make sure that you are sending an array of answers by changing the name to payment_methods[] 您需要通过将名称更改为payment_methods []来确保发送答案数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM