[英]Array of HTML radio button
I have an add contact form
with dynamically added radio buttons and input fields for the contact info: 我有一个
add contact form
其中包含动态添加的单选按钮和联系人信息的输入字段:
<tr>
<td><input class="case" type="checkbox"/></td>
<td style="text-align: center"><input type="radio" value="1" name="contact[principal][]" id="contact_1" class="icheck" @if( $contact->principal == 1) checked @endif> </td>
<td><input type="text" value="{{ $contact->name }}" data-type="ItemName" name="contact[name][]" id="name_1" class="form-control autocomplete_txt" autocomplete="off"></td>
<td><input type="text" value="{{ $contact->position }}" name="contact[position][]" id="position_1" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>
<td><input type="text" value="{{ $contact->phone }}" data-mask="phone-ext" name="contact[phone][]" id="tel_1" class="form-control changesNo" autocomplete="off" ondrop="return false;" onpaste="return false;"></td>
<td><input type="email" value="{{ $contact->email }}" name="contact[email][]" id="email_1" class="form-control changesNo" autocomplete="off" ondrop="return false;" onpaste="return false;"></td>
</tr>
Here is a: https://jsfiddle.net/66y6dtx0/ 这是一个: https : //jsfiddle.net/66y6dtx0/
Only one contact can be the principal and this is an example of what i receive from POST: 只能由一位联系人担任负责人,这是我从POST收到的示例:
[contact] => Array
(
[name] => Array
(
[0] => Jane Emerson
[1] => Jhon Doe
)
[position] => Array
(
[0] => Gerente
[1] => CEO
)
[phone] => Array
(
[0] => (888) 878-3969
[1] => (888) 578-8919
)
[email] => Array
(
[0] => jhon.e@gmail.com
[1] => jhon@example.org
)
[principal] => Array
(
[0] => 1
)
)
The problem is that when there are more than one contact, the index doesn't match the contact being selected as principal. 问题是,当有多个联系人时,索引与被选为主要联系人的索引不匹配。
How can i fix this? 我怎样才能解决这个问题?
Im using the Laravel framework is that helps. 我使用Laravel框架是有帮助的。
My solution to this problem: 我对这个问题的解决方案:
I added the row index using jquery to the name of the radio button and used jquery to deselect the others radio buttons with the help of this post: 我在这篇文章的帮助下将使用jquery的行索引添加到了单选按钮的名称中,并使用jquery取消了对其他单选按钮的选择:
radio different names - only check one 广播不同的名称-仅选中一个
Im still curious if there is a better solution. 我仍然好奇是否有更好的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.