dqy27359 2018-04-16 19:23
浏览 278
已采纳

如何正确更正此找到的具有非唯一ID错误的元素?

I have this form for a user to introduce some data to register in a congress.

First he needs to introduce some buyer information, then if there is some paid ticket type also some billing information. Then if the congress table has the column "collect_data_from_all_participants" as 1 the usre also needs to introduce information for each selected ticket type. This information for each ticket type is the name and surname of each participant so I have the name of the field "Name" as "name" and the field "Surname" with the name "surname". T

he issue is then in the console it appears :

 [DOM] Found 4 elements with non-unique id #name: 

`DOM] Found 3 elements with non-unique id #surname: 

Do you know what is the best approach to correct the issue?

<div class="registration_form mt-4">


    <form method="post" class="clearfix">

        <div class="tab-content registration_body bg-white" id="myTabContent">
            <div class="tab-pane fade show active clearfix" id="step1" role="tabpanel" aria-labelledby="home-tab">
                <h6>Buye information</h6>                    

                <div class="form-group font-size-sm">
                    <label for="name" class="text-gray">Name</label>
                    <input type="text" required class="form-control"  id="name" value="{{ (\Auth::check()) ? Auth::user()->name : old('name')}}">
                </div>
                <div class="form-group font-size-sm">
                    <label for="surname" class="text-gray">Surname</label>
                    <input type="text" required class="form-control" name="surname" id="surname" value="{{ (\Auth::check()) ? Auth::user()->surname : old('surname')}}">
                </div>
                <div class="form-group font-size-sm">
                    <label for="email" class="text-gray">Email</label>
                    <input type="text" required class="form-control" name="emai" id="email" value="{{ (\Auth::check()) ? Auth::user()->email : old('email')}}">
                </div>

                @if( array_sum(array_column($selectedRtypes, 'price')) > 0 )

                    <h6>Billing information</h6>

                    <div class="form-group font-size-sm">
                        <label for="name" class="text-gray">Name</label>
                        <input type="text" required class="form-control" id="name">
                    </div>
                    <div class="form-group font-size-sm">
                        <label for="inputName" class="text-gray">Country</label>
                        <input type="text" required class="form-control" id="inputName">
                    </div>
                   <!-- other fields -->

                @endif

                @if (!empty($allParticipants))
                    @if($allParticipants == 1)
                        @foreach($selectedRtypes as $k=>$selectedRtype)
                            <h6 class="text-heading-blue mb-3 pb-2 font-weight-bold">Participant - 1 - {{$k}}</h6>

                            <div class="form-group font-size-sm">
                                <label for="name" class="text-gray">Name</label>
                                <input type="text" required class="form-control" id="name" value="">
                            </div>
                            <div class="form-group font-size-sm">
                                <label for="surname" class="text-gray">Surname</label>
                                <input type="text" required class="form-control" name="surname" id="surname" value="">
                            </div>
                        @endforeach
                    @endif
                @endif

                <button type="button" href="#step2" data-toggle="tab" role="tab"
                        class="btn btn-primary btn float-right next-step">
                    Go to step 2
                </button>
            </div>
            <div class="tab-pane fade clearfix" id="step2" role="tabpanel" aria-labelledby="profile-tab">
                <form method="post" class="clearfix">

                    <h6>Select payment type</h6>

                   <!-- step 2 fields-->

                    <div class="text-right">
                    <button type="button" href="#step3" data-toggle="tab" role="tab"
                            class="btn btn-outline-primary prev-step">
                        Go to step 2
                    </button>
                    <button type="button" href="#step3" data-toggle="tab" role="tab"
                            class="btn btn-primary btn ml-2 next-step">
                        Go to step 3
                    </button>
                    </div>
                </form>
            </div>
            <div class="tab-pane clearfix fade" id="step3" role="tabpanel" aria-labelledby="contact-tab">
                <form method="post" class="clearfix">
                    <!-- step 3 fields-->
                </form>
            </div>
        </div>
    </form>
</div>
  • 写回答

2条回答 默认 最新

  • duanqian9593 2018-04-16 19:26
    关注

    Your problem is that all id attributes must be unique for a single document. From MDN:

    The id global attribute defines a unique identifier (ID) which must be unique in the whole document. Its purpose is to identify the element when linking (using a fragment identifier), scripting, or styling (with CSS).

    You are looping over <input> elements with id name and surname which causes multiple elements with the same id. If you remove the ids from these input elements, your warnings will go away.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?