How Do I use Chosen iquery Search Dropdown with Modal PoPup

abiodunajai 396 Reputation points
2023-07-23T17:38:59.69+00:00

Please I have an HTML modal that shows a Dropdown List.

Everything works well except that I want the user to search the List or select by scrolling through the list. The scrolling is working but the searching using the chosen jQuery is not working.

I will appreciate any assistance to make it work, please.

Below is my Script.

<a href="#showDialog" class="btn btn-primary" title="Apportionment" data-toggle="modal" data-id="">Insurers</a>


      <div class="row">
            <div class="col-md-12 col-sm-8 col-xs-12 col-xs-offset-0">
                <div id="showDialog" tabindex="-1" role="dialog" aria-labelledby="showDialogLabel" aria-hidden="true" class="modal fade" data-backdrop="static" data-keyboard="false">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h4 class="modal-title" id="showDialogLabel">Risk Apportionment</h4>
                            </div>
                            <div class="modal-body">
                                <div class="table-responsive">
                                    <table id="requestItems" class="table table-bordered table-striped table-hover" cellspacing="0">
                                            <tr>
                                                <td>
                                                    <div " class="btn btn-primary btn-sm">
                                                        <strong></strong><span class="glyphicon glyphicon-remove center-block"></span>
                                                    </div>
                                                </td>
                                                <td>Insurer Branch Code</td>
                                                <td>Lead Insurer</td>
                                                <td>Percentage Covered</td>
                                                <td>Confirm?</td>

                                            </tr>
                                        </thead>

                                        @{if (!string.IsNullOrEmpty(Model.Underwriting_PolicyFile.PolicyRefCode))
                                        {
                                            var prefx4 = "Underwriting_InsurerPolicyDistribution";
                                            var prefx6 = prefx4 + ".index";
                                            for (var i = 1; i <= Model.Underwriting_InsurerPolicyDistribution.Count; i++)
                                            {
                                                var itemIndex3 = string.Format("X{0}", i);
                                                var n7 = string.Format("{1}[X{0}].PolicyRefCode", i, prefx4);
                                                var n8 = string.Format("{1}[X{0}].InsBranchCode", i, prefx4);
                                                var n9 = string.Format("{1}[X{0}].InsuerLeadCode", i, prefx4);
                                                var n10 = string.Format("{1}[X{0}].PercentageCover", i, prefx4);
                                                var n11= string.Format("{1}[X{0}].isConfirmed", i, prefx4);
                                                <tr>
                                                    <td>
                                                        <input type="hidden" name="@prefx6" value="@itemIndex3" />
                                                        @Html.Hidden(n7, Model.Underwriting_InsurerPolicyDistribution[i - 1].PolicyRefCode, new { id = n7 })
                                                        <button type="button" style="background-color:#89006e !important; color:#fff; text-align:center" class="btn-primary btn-xs delbtn"><span class="glyphicon glyphicon-remove"></span></button>
                                                    </td>                                                    
                                                    <td>
                                                        @Html.DropDownList(n8, new SelectList(Html.InsurerBranchDropDownList(), "InsBranchCode", "FullDescription", Model.Underwriting_InsurerPolicyDistribution[i - 1].InsBranchCode), new { id = n8, @class = "form-control input-sm" })
                                                        @Html.ValidationMessage(n8, "", new { @class = "text-danger" })
                                                    </td>
                                                    <td>
                                                        @Html.CheckBox(n9, Model.Underwriting_InsurerPolicyDistribution[i - 1].InsuerLeadCode, new { id = n9, @class = "form-control input-sm" })
                                                        @Html.ValidationMessage(n9, "", new { @class = "text-danger" })
                                                    </td>
                                                    <td>
                                                        @Html.TextBox(n10, Model.Underwriting_InsurerPolicyDistribution[i - 1].PercentageCover, new { id = n10, @class = "form-control input-sm", @style = "width: 65px;" })
                                                        @Html.ValidationMessage(n10, "", new { @class = "text-danger" })
                                                    </td>
                                                    <td>
                                                        <div class="form-check" type="checkbox">
                                                            @Html.CheckBox(n11, Model.Underwriting_InsurerPolicyDistribution[i - 1].isConfirmed, new { id = n11, @class = "form-check-input" })
                                                            @Html.ValidationMessage(n11, "", new { @class = "text-danger" })
                                                        </div>
                                                    </td>
                                                    
                                                </tr>
                                            }
                                           }

                                        }
                                    </table>
                                    <input type="submit" class="btn btn-primary" value="Add New" onclick="addRow('requestItems'); return false;" />
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-primary" data-dismiss="modal">Next</button>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>




@section scripts {
    <script src="~/Scripts/chosen.jquery.min.js"></script>

<script type="text/javascript">

$(document).ready(function () {

        $(document).ready(ReadyMenu);


        $("#Underwriting_InsurerPolicyDistribution[X1].InsBranchCode").chosen({
            disable_search_threshold: 5
        });


  });

</script>

Best Regards

Abiodunajai

Developer technologies | ASP.NET | Other
Developer technologies | C#
{count} votes

Accepted answer
  1. Lan Huang-MSFT 30,191 Reputation points Microsoft External Staff
    2023-07-24T03:32:54.2533333+00:00

    Hi @abiodunajai,

    You'd better provide the rest of your code so we can reproduce your issue.

    Based on the code you've provided so far, you'd be better off using a class to position the dropdown. instead of an ID.

    @Html.DropDownList(n8, new SelectList(Html.InsurerBranchDropDownList(), "InsBranchCode", "FullDescription", Model.Underwriting_InsurerPolicyDistribution[i - 1].InsBranchCode), new { id = n8, @class = "form-control input-sm test" })
    
    
    
    @section scripts {
        <script src="~/Scripts/chosen.jquery.min.js"></script>
        <link href="~/Content/chosen.css" rel="stylesheet" />
        <script type="text/javascript">
            $(document).ready(function () {
    
                $(".test").chosen({
                    disable_search_threshold: 5
                });
            });
    
        </script>
    }
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.