Selectpicker ค่า value ไม่ออกอ่ะครับรบกวนช่วยดูให้ผมหน่อยครับ
ผมใช้ Selectpicker ค่า value ไม่ออกอ่ะครับรบกวนช่วยดูให้ผมหน่อยครับ
ผมไม่แน่เกิดจากสาเหตุดังต่อไปนี้หรือเปล่า
1.ผมใช้วิธีสร้าง datatable แล้วผมใช้ foreach เลยทำให้ Name กับ Id มองไม่เห็น แล้วทำให้ซ้ำกัน
2. ผม model เพื่อทำการสร้างหน้าแก้ไข แล้วในนั้นมี from เพื่อทำการส่งค่า Post
3. ผมใช้ ajax
รบกวนพวกช่วยดูให้ผมหน่อยนครับ Thank you so much.
Code (PHP)
หน้า datatable
Code (PHP)
<div class="table-responsive">
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th style="width:1%">No</th>
<th>IMIP</th>
<th>Department</th>
<th style="width:20%">Master</th>
<th style="width:20%">Type</th>
<th>Location</th>
<th>Status</th>
<th>Date</th>
<th style="width:1%" class="text-center">Edit</th>
</tr>
</thead>
<tbody>
<?php
$ListTBReserve = json_decode(Rev_List_TB_List_Reserve($season_date, $view), true);
$No = 0;
foreach ($ListTBReserve as $row) {
$No += 1;
$RevID = ($view != 'season') ? $row['Rev_ID'] : '';
$Rev_UserNum = ($view != 'season') ? $row['Rev_UserNum'] : '';
$Emp_EngName = $row['Emp_EngName'];
$DepName = ($view != 'season') ? $row['Dep_Nam'] : '';
$RevMasNum = ($view != 'season') ? $row['Rev_MasNum'] : '';
$RevMasName = $row['Mas_Name'];
$RevTypeNum = ($view != 'season') ? $row['Rev_TypeNum'] : '';
$RevTypeName = $row['Type_Name'];
$RevLocation = ($view != 'season') ? $row['Rev_Location'] : '';
$RevDate = $row['Rev_Date'];
$RevFrmDate = DateTime::createFromFormat('Ymd', $row['Rev_Date'])->format('d/m/Y');
$RevUpdtm = $row['Rev_UpDtm'];
$RevFrmYear = DateTime::createFromFormat('YmdHis', $RevUpdtm)->format('Y');
$RevFrmMoth = DateTime::createFromFormat('YmdHis', $RevUpdtm)->format('m');
$RevFile = $row['Rev_File'];
$RevStatus = ($view != 'season') ? Rev_List_chech_status($row['Rev_Status']) : '';
$Rev_Remark = $row['Rev_Remark'];
?>
<tr>
<td><?php echo $No ?></td>
<td><?php echo '<p class="text-info">' . $Rev_UserNum . '</p>' ?></td>
<td><?php echo $DepName ?></td>
<td><?php echo '<p>' . $RevMasName . '</p>' ?></td>
<td><?php echo '<p>' . $RevTypeName . '</p>' ?></td>
<td><?php echo '<p>' . $RevLocation . '</p>' ?></td>
<td class="text-center"><?php echo '<p>' . $RevStatus . '</p>' ?></td>
<td><?php echo '<p>' . $RevFrmDate . '</p>' ?></td>
<td style="width:30%" class="text-center">
<?php if ($row['Rev_Status'] == 'wait') { ?>
<button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#exampleModalEditListRev<?php echo $RevID ?>"><i class="far fa-edit"></i></button>
<button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#exampleModalWaitinstallListRev<?php echo $RevID ?>"><i class="fas fa-check"></i></button>
<button onClick="deleteRev('<?php echo $RevID ?>')" type="button" class="btn btn-danger btn-sm"><i class="far fa-trash-alt"></i></button>
<?php } ?>
</td>
</tr>
<?php
include 'manage/form/frm-reserve/frm-list/mod-Edit.php';
include 'manage/form/frm-reserve/frm-list/mod-Wait-install.php'; // หน้า Model ที่มีปัญหา select picket
}
?>
</tbody>
<tfoot>
<tr>
<th style="width:1%">No</th>
<th>IMIP</th>
<th>Department</th>
<th style="width:20%">Master</th>
<th style="width:20%">Type</th>
<th>Location</th>
<th>Status</th>
<th>Date</th>
<th style="width:1%" class="text-center">Edit</th>
</tr>
</tfoot>
</table>
</div>
หน้า from model Edit
<div class="modal fade" id="exampleModalWaitinstallListRev<?php echo $RevID ?>" tabindex="-1" role="dialog" aria-labelledby="scrollableModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-full-width" role="document">
<div class="modal-content">
<div class="modal-header modal-colored-header bg-success">
<h5 class="modal-title" id="scrollableModalTitle">Wait install employee <?php echo ' "' . $Rev_UserNum . '" ' ?> reserve device</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form class="needs-validation" id="Wait-install-Rev<?php echo $RevID ?>" name="Wait-install-Rev<?php echo $RevID ?>">
<div class="modal-body">
<div class="row">
<div class="col-lg-12 col-sm-12">
<h3><i class="far fa-address-card" style="font-size: 30px;"></i> Information employee reserve device</h3>
<hr>
<div class="row">
<div class="col-lg-4 col-sm-12">
<div class="form-group mb-2">
<label for="exampleFormControlSelect1">IMIP: <o class="text-info"><?php echo $Rev_UserNum ?></o></label>
</div>
<div class="form-group mb-2">
<label for="exampleFormControlSelect1">Type device: <o class="text-info"><?php echo $RevTypeName ?></o></label>
</div>
</div>
<div class="col-lg-4 col-sm-12">
<div class="form-group mb-2">
<label for="exampleFormControlSelect1">Name: <o class="text-info"><?php echo $Emp_EngName ?></o></label>
</div>
<div class="form-group mb-2">
<label for="exampleFormControlSelect1">Location: <o class="text-info"><?php echo $RevLocation ?></o></label>
</div>
</div>
<div class="col-lg-4 col-sm-12">
<div class="form-group mb-2">
<label for="exampleFormControlSelect1">Mater: <o class="text-info"><?php echo $RevMasName ?></o></label>
</div>
<div class="form-group mb-2">
<label for="exampleFormControlSelect1">Approve flow date: <o class="text-info"><?php echo $RevFrmDate ?></o></label>
</div>
</div>
<div class="col-12">
<div class="form-group mb-2">
<label for="exampleFormControlSelect1">Remark: <o class="text-info"><?php echo $Rev_Remark ?></o></label>
</div>
</div>
</div>
<hr>
</div>
<?php echo Rev_Wait_install::SelectFromSerialDevice($RevTypeNum, $RevTypeName); ?>
<div class="col-lg-12 col-sm-12">
<br>
<h4 class="text-info">Detail device</h4>
<hr>
</div>
<div class="col-lg-6 col-sm-12">
<label for="exampleFormControlSelect1">IP Address: </label>
<input type="text" class="form-control" id="IPAddress" name="IPAddress" type="text" value="">
</div>
<div class="col-lg-6 col-sm-12">
<label for="exampleFormControlSelect1">MAC Address: </label>
<input type="text" class="form-control" id="MacAddress" name="MacAddress" type="text" value="">
</div>
<div class="col-lg-6 col-sm-12">
<label for="exampleFormControlSelect1">Driver Name (Windows): </label>
<input type="text" class="form-control" id="DriverName" name="DriverName" type="text" value="">
</div>
<div class="col-lg-6 col-sm-12">
<label for="exampleFormControlSelect1">OS : </label>
<!-- <select class="selectpicker form-control item_unit OS" data-live-search="true" name="OS" id="OS">
<?php echo Rev_List_Select_Master_os('') ?>
</select> -->
<select name="OS" id="OS" class="selectpicker">
<option value="CD23E546-9BD8-40FD-BD9A-3E2CBAD81A39">Dennis</option>
<option value="4DDCC643-0DE2-4B78-8393-33A716E3AFF4">Robert</option>
<option value="D3017807-86E2-4E56-9F28-961202FFF095">George</option>
<option value="991C2782-971E-41F8-B532-32E005F6A349">Ivanhoe</option>
</select>
</div>
<div class="col-lg-12 col-sm-12">
<br>
<h4 class="text-info">status install</h4>
<hr>
</div>
<div class="col-lg-6 col-sm-12">
<label for="exampleFormControlSelect1">Status install: </label>
<select class="selectpicker form-control item_unit" data-show-subtext='true' data-live-search="true" name="status" id="status">
<?php echo Rev_List_Select_Master_status_install('') ?>
</select>
</div>
</div>
<br>
<div class="modal-footer">
<input type="hidden" id="Wiat_In_IMIP" name="Wiat_In_IMIP" value="<?php echo $Rev_UserNum ?>">
<input type="hidden" id="Wiat_In_RevNum" name="Wiat_In_RevNum" value="<?php echo $RevID ?>">
<input type="hidden" id="Wiat_In_TypeNum" name="Wiat_In_TypeNum" value="<?php echo $RevTypeNum ?>">
<button type="button" class="btn btn-light" data-dismiss="modal">Close</button>
<button type="submit" name="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
<script>
$('#editdate').datepicker({
format: 'dd/mm/yyyy'
});
// $('.OS').on("selectpicker:select", function(e) {
// //alert($('.OS').select2().val());
// $('#OSname').val($('.OS').select2().val());
// });
$('select[name=OS]').selectpicker();
$(document).ready(function() {
$("#Wait-install-Rev<?php echo $RevID ?>").on("submit", function(event) {
console.log($("#Wait-install-Rev<?php echo $RevID ?>")[0])
// var status = "Status_install" + "<?php echo $RevID ?>"
// var r = document.getElementById(status).value;
var fdata = new FormData($("#Wait-install-Rev<?php echo $RevID ?>")[0]);
console.log('data form', fdata);
Swal.fire({
title: "<h1>Are you sure?</h1>",
text: "Confirm edit this reserve install device!",
icon: "info",
showCancelButton: true,
confirmButtonClass: "btn-primary ml-1 h3",
cancelButtonClass: "btn-danger ml-1 h3",
confirmButtonText: "OK",
showLoaderOnConfirm: true,
}).then((result) => {
if (result.value) {
$.ajax({
url: "manage/form/frm-reserve/frm-list/action/wait-in-list.php",
method: "POST",
data: fdata,
confirmButtonClass: "btn-primary ml-1",
contentType: false,
processData: false,
// beforeSend: function(result) {
// let timerInterval;
// Swal.fire({
// title: "<h1>loading data!</h1>",
// html: "<p>Please wait for the system to loading data.</p><br><div class='spinner-grow text-primary' role='status'><span class='sr-only'>Loading...</span></div><div class='spinner-grow text-primary' role='status'><span class='sr-only'>Loading...</span></div><div class='spinner-grow text-primary' role='status'><span class='sr-only'>Loading...</span></div><div class='spinner-grow text-primary' role='status'><span class='sr-only'>Loading...</span></div><div class='spinner-grow text-primary' role='status'><span class='sr-only'>Loading...</span></div>",
// timer: 99999999,
// timerProgressBar: true,
// showConfirmButton: false,
// didOpen: () => {
// Swal.showLoading();
// const b = Swal.getHtmlContainer().querySelector("b");
// timerInterval = setInterval(() => {
// b.textContent = Swal.getTimerLeft();
// }, 100);
// },
// willClose: () => {
// clearInterval(timerInterval);
// },
// }).then((result) => {
// /* Read more about handling dismissals below */
// if (result.dismiss === Swal.DismissReason.timer) {
// console.log("I was closed by the timer");
// }
// });
// },
// success: function(result) {
// Swal.fire({
// title: "<h1>Complete!</h1>",
// text: "Your data has been brand.",
// icon: "success",
// confirmButtonClass: "btn-primary ml-1 h3",
// // timer: 1700,
// }).then((result) => {
// location.reload();
// });
// $("#Wait-install-Rev<?php echo $RevID ?>").reset();
// },
error: function(data) {
Swal.fire({
title: "<h1>Failed!</h1>",
text: "Can't add your information something went wrong!",
icon: "error",
confirmButtonClass: "btn-primary ml-1 h3",
// timer: 1700,
}).then((result) => {
location.reload();;
});
$("#Wait-install-Rev<?php echo $RevID ?>").reset();
},
});
}
});
return false;
});
});
</script>
Tag : PHP, MySQL, HTML5, JavaScript, Ajax, jQuery
Date :
2022-02-12 08:32:28
By :
mustakeam
View :
775
Reply :
1
การสื่อสารที่ผิดพลากกกก
"ผมใช้ Selectpicker / ผมใช้วิธีสร้าง datatable / ผม model เพื่อ..."
ดูโค้ดแล้วคุณไม่น่าได้ใช้ทั้งสามอย่างนี้
Selectpicker -> bootstrap-select ?
datatable -> ไหน instance?
model -> modal ?
การแก้ปัญหาเบื้องต้น คลิกดูตรง console (16 แดงๆ) แล้วนำมาดู หรือไล่แก้เองตามรายละเอียดที่มันแจ้ง
Date :
2022-02-12 17:02:28
By :
009
Load balance : Server 05