简体   繁体   English

Bootstrap-datetimepicker-动态添加显示在错误的区域

[英]Bootstrap-datetimepicker - dynamically add shows up in wrong area

So after writing to the DB through ajax. 因此,通过ajax写入DB之后。 my success function. 我的成功职能。 builds an element and appends it to the table. 构建一个元素并将其附加到表中。 Then after it appends it to the table it calls a datetimepicker on that new appended row. 然后,将其追加到表后,在新追加的行上调用datetimepicker。 However the date time picker (calendar) shows up somewhere completely weird. 但是日期时间选择器(日历)显示在一个完全奇怪的地方。 See screen shot. 参见屏幕截图。

One thing I should mention is that these notes are in a tab-pane it looks like 我应该提到的一件事是,这些注释在选项卡窗格中看起来像

Please see below for the view and the javascript 请参阅下面的视图和javascript

VIEW: 视图:

<div class="panel-body">
    @if (session('status'))
        <div class="alert alert-success">
            {{ session('status') }}
        </div>
    @endif
    <ul  class="nav nav-pills">
            <li class="active">
                <a  href="#cdetails" data-toggle="tab">Details</a>
            </li>
            <li>
                <a href="#Quotes" data-toggle="tab">Quotes</a>
            </li>
            <li>
                <a href="#Notes" data-toggle="tab">Notes</a>
            </li>
            <li>
                <a href="#Documents" data-toggle="tab">Documents</a>
            </li>
        </ul>
    <div class="tab-content">
        <div id="cdetails" class="tab-pane active">
            <table class="table ">
                <thead>
                </thead>
                <tbody>
                    <tr ><td colspan="4"></td></tr>

                    <tr><td><b>Code</b></td><td colspan="3">{{$item->code}}</td></tr>
                    <tr><td><b>Name</b></td><td colspan="3">{{$item->name}}</td></tr>
                    <tr><td><b>Customer</b></td><td colspan="3">{{$item->customer->company}}</td></tr>
                    <tr><td><b>Contract Type</b></td><td colspan="3">{{$item->contype}}</td></tr>
                    <tr><td><b>Contract Amount</b></td><td colspan="3">{{$item->contractAmount}}</td></tr>
                    <tr><td><b>Hourly Rate</b></td><td colspan="3">{{$item->rate}}</td></tr>
                </tbody>
            </table>
            @if(1 == 2)
                <h3>Phases <button class="btn btn-sm btn-primary pull-right" href="#assigntemplate" data-toggle="modal" >Assign a Template</button></h3><hr />
                <table class="table">
                    <thead>
                        <tr>
                            <th>Name</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach($item->phases as $p)
                            <tr>
                                <td>{{$p->name}}</td>
                            </tr>
                        @endforeach
                    </tbody>
                </table>
            @endif
        </div><!-- end details tab -->
        <div id="Quotes" class="tab-pane">

        </div><!-- end of quotes tab -->
        <div id="Notes" class="tab-pane">
            <table class="table">
                <thead>
                    <tr >
                        <th class="">Date</th>
                        <th class="col-md-8">Note</th>
                        <th class="">Action</th>
                    </tr>
                </thead>
                <tbody id="noteListTBody">
                <button href="#addNote" data-toggle="modal" class="btn btn-info pull-right" style="color:white; margin:20px 8px 0 0; position:relative; top:-50px; padding:3px; width:30px; height:30x;"><span class="glyphicon glyphicon-plus"></span></button>
                    @foreach($item->notes as $note)
                        <tr data-id="{{$note->id}}">
                            <td><input type="text" class="form-control dpick" name="date" disabled value="{{Carbon\Carbon::parse($note->date)->format('m/d/Y')}}" ></td>
                            <td><textarea type="text" class="form-control dnote"  name="note" disabled>{{$note->note}}</textarea></td>
                            <td>
                                <button class="btn btn-danger pull-right btnDeleteNote" href="#noteDelete" data-toggle="modal"><span class="glyphicon glyphicon-trash"></span></button>
                                <button class="btn btn-primary pull-right btnEditNote"><span class="glyphicon glyphicon-pencil"></span></button>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div><!-- end of notes tab -->
    </div>

JAVASCRIPT JAVASCRIPT

$.ajax({
        type: 'POST',
        url: "/api/notes",
        data: {
            '_token'        : ajaxtoken,
            'item_id'       : itemID,
            'item_type'     : itemType,
            'user_id'       : userID,
            'date'          : dateValue,
            'note'          : noteValue


        },
        success: function(result) {
            console.log(result);
            // noteListTBody
            var noteRow = `
                <tr data-id="`+result.item_id+`">
                    <td><input type="text" class="form-control dpick" name="date" disabled value="`+dateObject+`" ></td>
                    <td><textarea type="text" class="form-control"  name="note" disabled>`+noteValue+`</textarea></td>
                    <td>
                        <button class="btn btn-danger pull-right btnDeleteNote" href="#noteDelete" data-toggle="modal"><span class="glyphicon glyphicon-trash"></span></button>
                        <button class="btn btn-primary pull-right btnEditNote" ><span class="glyphicon glyphicon-pencil"></span></button>
                    </td>
                </tr>
            `;

            $('#noteListTBody').append(noteRow);

            $('.btnCloseModal').click();
            $('#noteListTBody tr[data-id="'+result.item_id+'"]').find('.dpick').datetimepicker({format: 'MM/DD/YYYY'});

        }
    });

日期时间选择器图像。失败

点击1

点击2

点击3

So I do not know the exact fact. 所以我不知道确切的事实。 It could be one of the 2 possible reasons. 这可能是两个可能的原因之一。

  1. datetimepicker - requires a div wrapper for the target relative positioning datetimepicker-需要div包装器用于目标相对位置
  2. datetimepicker - requires an input-group div wrapper for the target relative positioning datetimepicker-需要输入组div包装器用于目标相对定位

Either way. 无论哪种方式。 I used the following code from their site. 我在他们的网站上使用了以下代码。

<div class='input-group date' id='datetimepicker1'>
    <input type='text' class="form-control" />
    <span class="input-group-addon">
        <span class="glyphicon glyphicon-calendar"></span>
    </span>
</div>

Once I did this. 一旦我做到了。 And moved the datepicker from targeting the input directly to targeting the group around it (the div) it worked in it's relative positioning perfectly. 并将datepicker从直接定位输入定位到定位在其相对位置完美工作的周围的组(div)。

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

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