Get date from one datetime picker and display in second datetime picker with disbable - tempus-dominus-datetimepicker

i'm using TempusDominus Bootstrap4 DateTime Picker. I have two datetimepicker from date and to date. I want that when user select date from First DateTime picker then disables date in the second datetimepicker.
I am following this link and want the same thing but it's not working on my side. I am not sure where is the problem.
<div class="col-md-3">
<div class="input-group date" id="startTime" data-target-input="nearest">
<input type="text" name="startTime" id="startDate" class="form-control datetimepicker-input" data-target="#startTime" value="">
<div class="input-group-append" data-target="#startTime" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar" aria-hidden="true"></i></div>
</div>
</div>
</div>
<div class="col-md-3">
<div class="input-group date" id="endTime" data-target-input="nearest">
<input type="text" name="endTime" id="endDate" class="form-control datetimepicker-input" data-target="#endTime" value="">
<div class="input-group-append" data-target="#endTime" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar" aria-hidden="true"></i></div>
</div>
</div>
</div>
Javascript code
<script>
$('#startTime').datetimepicker({
format: 'DD.MM.YYYY',
minDate:new Date()
});
$('#endTime').datetimepicker({
format: 'DD.MM.YYYY',
minDate:new Date($('#startDate').val())
});
$('#startDate').on("blur",function(){
$('#endTime').data("DateTimePicker").destroy();
$('#endTime').datetimepicker({
format: 'DD.MM.YYYY',
minDate:new Date($('#startDate').val())
});
});
</script>

Related

Laravel - Display Image in Modal while editing

I am a beginner of laravel. I want to edit a record which contains image, but it just show the input type for file same as insert records, instead of displaying the image. I have no ideas how to make it. Any comments are appreciated. Thanks.
Modal
<div class="modal-body">
<form method="POST" id="memberCardForm" name="memberCardForm" class="form-horizontal" enctype="multipart/form-data">
#csrf
<input type="hidden" name="id" id="id">
<div class="form-group">
<label for="">Card Type</label>
<div class="col-sm-12">
<input type="text" class="form-control" id="card_type" name="card_type" maxlength="50" required>
</div>
</div>
<div class="form-group">
<label for="">Description</label>
<div class="col-sm-12">
<input type="text" class="form-control" id="card_desc" name="card_desc" maxlength="50" required>
</div>
</div>
<div class="form-group">
<label for="">Entitlement</label>
<div class="col-sm-12">
<input type="text" class="form-control" id="card_entitlement" name="card_entitlement" maxlength="50">
</div>
</div>
<div class="form-group">
<label for="">Card Image</label>
<div class="col-sm-12">
<input type="file" class="form-control" id="image" name="image" required>
</div>
</div>
<div class="modal-footer">
Close
<button type="submit" id="saveBtn" class="btn btn-success">Save</button>
</div>
</form>
</div>
JS for Edit record
//Edit
$('body').on('click', '.editRecord', function() {
var id = $(this).data('id');
$.get("{{ url('membercards/edit') }}" + '/' + id, function(data) {
$('#exampleModalLabel').html("Edit Member Card");
$('#saveBtn').html('Save');
$('#exampleModal').modal('show');
$('#id').val(data.id);
$('#card_type').val(data.card_type);
$('#card_desc').val(data.card_desc);
$('#card_entitlement').val(data.card_entitlement);
$('#image').val(data.image);
})
});

in my laravel project some datas are not passed to controller from form submit.What could be the reasons?

in my laravel project i have made a form with input field name,size,price,etc. My problem is that when i type name in name field datas arenot passed to controller.This is happening only to some specific names.For some other names working fine.And this problem is raised in live in local working fine
below is form blade
<form class="form-horizontal form-label-left" method="post"
action="{{route('product')}}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group col-lg-6" >
<label for="select-from">Select Catagory:<span class="required" style="color:red;">*</span></label>
<select class="form-control" id="category" name="category">
<option value="">Choose</option>
#foreach($allcategory as $cat)
<option value="{{$cat->id}}">{{$cat->name}}</option>
#endforeach
</select>
</div>
<script type="text/javascript">
$(document).ready(function(){
$(document).on('change','#category',function(){
var a = $(this).val();
$.ajax({
type:'get',
url: '{{URL::to('#dashboard#/childcategory-section/submenu-choose')}}',
data:{'id':a},
success:function(datas){
$("select#submenu").empty();
$.each(datas,function(i,data){
$("select#submenu").append('<option value="'+data.id+'"> '+data.name+'</option>');
});
}
});
});
});
</script>
<div class="form-group col-lg-6" >
<label for="select-from">Select SubCategory:<span class="required" style="color:red;">*</span></label>
<select name="submenu_id" id="submenu" class="form-control">
<option value="">Choose</option>
</select>
</div>
<div class="form-group col-lg-12">
<label for="category">Product Name <span class="required" style="color:red;">*</span> </label>
<div>
<input type="text" name="name" required class="form-control">
</div>
</div>
<div class="form-group col-lg-6">
<label for="category">Image <span class="required" style="color:red;">*</span> </label>
<div>
<input type="file" name="image" required class="form-control">
</div>
</div>
<div class="form-group col-lg-12">
<label for="category">Old Price <span class="required" style="color:red;">*</span> </label>
<div>
<input type="text" name="old_price" required class="form-control">
</div>
</div>
<div class="form-group col-lg-12">
<label for="category">New Price <span class="required" style="color:red;">*</span> </label>
<div>
<input type="text" name="new_price" required class="form-control">
</div>
</div>
<script src="{{URL::to('ckeditorfull/ckeditor/ckeditor.js')}}"></script>
<div class="form-group col-lg-12">
<label for="category">Detail <span class="required" style="color:red;">*</span> </label>
<div>
<textarea class="form-control" id="detail" name="detail" ></textarea>
</div>
</div>
<script>
CKEDITOR.replace( 'detail');
</script>
<div class="ln_solid"></div>
<div class="form-group ">
<div>
<button type="submit" class="btn btn-success pull-right" style="background: #1abb9c;">Submit</button>
</div>
</div>
below is controller
public function add_action(Request $request){
//dd($request->all());
$datas=new Product();
$this->validate($request,['name'=>'required|unique:products',
'image'=>'required',
'old_price'=>'required',
'new_price'=>'required',
'detail'=>'required',
'total_products'=>'required',
'size'=>'required',
'total_sizeproducts'=>'required']);
$datas->category_id=$request->category;
$datas->menu_id=$request->submenu_id;
$datas->name=$request->name;
$datas->slug=str_slug($request->name);
if($request->hasFile('image')){
$file=$request->file('image');
$filename=time().$file->getClientOriginalName();
$file->move(public_path().'/backend/images/products/',$filename);
$datas->image=$filename;
}
$datas->new_price=$request->new_price;
$datas->old_price=$request->old_price;
$datas->rating=$request->rating;
$datas->brand=$request->brand;
$datas->availability=$request->availability;
$datas->total_products=$request->total_products;
$datas->discount=$request->discount;
$datas->detail=$request->detail;
$datas->save();
}
return redirect()->back()->with('success','products added successfully!!!');
}
below is route
Route::group(['namespace'=>'product','prefix'=>'product','middleware'=>'auth'],function (){
Route::get('/','ProductController#add')->name('product');
Route::post('/','ProductController#add_action');
});
Post some code. But you can use dd($request) and you will be able to see the data thats being sent to the controller. Make sure you are using the correct route for that action.

Get dealership under a company

I have branch index page it contains 2 drop-down menu called company and dealership when i click on company it contains a company i created when click on a company the corresponding dealership should list in the dealership dropdown. i used eloqent straightly into index page i did that because the i can't access the company and dealership in the index page
Index
#include('theme.header')
<?php use Illuminate\Support\Facades\DB;?>
<div class="page-content-wrapper ">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
</div>
<h4 class="page-title">Branch Management</h4>
</div>
</div>
</div>
<!-- end page title end breadcrumb -->
<div class="row">
<div class="col-12">
<div class="card m-b-30">
<div class="card-body">
<h4 class="mt-0 header-title">Branch</h4>
<br>
<br>
<form id="form" method="post" action="{{route('branch.store')}}">
{{csrf_field()}}
<div class="form-group row">
<label class="col-sm-2 col-form-label">Company</label>
<div class="col-sm-10">
<select class="form-control" id="company" name="company">
<option>Select Company</option>
#foreach(\App\Company::all()->where('status','0') as $company)
<option value="{{$company->comp_id}}">{{$company->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-2 col-form-label">Dealership</label>
<div class="col-sm-10">
<select class="form-control" id="dealer" name=" dealer">
<option>Select Dealership</option>
#foreach(\App\Dealership::join('companies','comp_id','=','dealerships.comp_id')->where('status','0') as $dealership)
<option value="{{$dealership->dlr_id}}">{{$dealership->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group row">
<label for="example-text-input" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input class="form-control" type="email" id="email" name="email" required>
</div>
</div>
<div class="form-group row">
<label for="example-text-input" class="col-sm-2 col-form-label">Branch Name</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="branch" name="branch" required>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
<button class="btn btn-primary" id="btn_save" data-toggle="modal"
data-target="#create" type="submit">Save
</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
#include('theme.footer')
First thing first. You need to change queries.
Company::where(‘status’, 0)->get();
And next you missed the tailing get() in the next dropdown.
And why are you not using relationships to query?
Like Muhammad Naumann already said you have to use the get() method to get the actual data:
Company::where(‘status’, 0)->get();
On the company select field you could add an event listener like onChange. In this listener you run a ajax get request to fetch the dealerships for the selected company.
I figured it out with Ajax.
Create a custom function in controller file. In this case Branch controller, this function contains query builder to retrieve the data
Write Ajax, in the index file, the dealership dropdown is hidden default when you select the company the dropdown will show corresponding data.
Index File
#include('theme.header')
<?php use Illuminate\Support\Facades\DB;?>
<script language="javascript">
/*--- Fliter dealership corressponging company---*/
$(document).ready(function () {
$('#dealership_div').hide();
$('#company').change(function () {
alert('hello');
$('#dealership_div').show();
let id = this.value;
$.ajax({
url: '/filter_dealer',
type: "post",
data: {option: id},
success: function (data) {
$('#dealer')
.find('option')
.remove()
.end()
.append(" <option value=''>--- Select dealership ---</option>")
$.each(data, function (key, value) {
$('#dealer')
.append($("<option></option>")
.attr('value', value['dlr_id'])
.text(value['name'])
);
});
},
error: function () {
alert("Error occurred While Processing");
}
});
});
});
</script>
<div class="page-content-wrapper ">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
</div>
<h4 class="page-title">Branch Management</h4>
</div>
</div>
</div>
<!-- end page title end breadcrumb -->
<div class="row">
<div class="col-12">
<div class="card m-b-30">
<div class="card-body">
<h4 class="mt-0 header-title">Branch</h4>
<br>
<br>
<form id="form" method="post" action="{{route('branch.store')}}">
{{csrf_field()}}
<div class="form-group row">
<label class="col-sm-2 col-form-label">Company</label>
<div class="col-sm-10">
<select class="form-control" id="company" name="company">
<option>Select Company</option>
#foreach(\App\Company::all()->where('status','0') as $company)
<option value="{{$company->comp_id}}">{{$company->name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group row" id="dealership_div">
<label class="col-sm-2 col-form-label">Dealership</label>
<div class="col-sm-10">
<select class="form-control" id="dealer" name=" dealer">
<option></option>
</select>
</div>
</div>
<div class="form-group row">
<label for="example-text-input" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-10">
<input class="form-control" type="email" id="email" name="email" required>
</div>
</div>
<div class="form-group row">
<label for="example-text-input" class="col-sm-2 col-form-label">Branch Name</label>
<div class="col-sm-10">
<input class="form-control" type="text" id="branch" name="branch" required>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="page-title-box">
<div class="btn-group float-right">
<button class="btn btn-primary" id="btn_save" data-toggle="modal"
data-target="#create" type="submit">Save
</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
Branch Controller File With a custom function
public function filter_dealer(Request $request)
{
$company_id=$request->input('option');
$dealership=DB::table('dealerships')->select('dlr_id','name')->where([['comp_id','=',$company_id],['status','=','0']])->get();
return response()->json($dealership);
}
Route File
Route::post('filter_dealer', 'BranchController#filter_dealer')->name('filter_dealer');
If you want to dynamically change the contents of dealership dropdown, on the event of changing the company dropdown, you should use javascript, jquery or similar javascript framework, because PHP is a server side scripting language and require page refresh to change the contents of a web page.

how to select and show data comment by id post in codeigniter

master peace of codeigniter. im new user for this framework.
i have problem to show comment data by id_diskusi in the single post of diskusi. i try to show data using 'where' in the lybrary code but its still not show the data. i hope the people at there can help me & solved this problem.
i use library to get data from database
public function setuju(){
$data=$this->CI->db->query("SELECT komentar.id AS id,
komentar.diskusi_id AS id_diskusi,
komentar.pilih AS pilih,
komentar.nama AS nama,
komentar.email AS email,
komentar.pesan AS pesan,
komentar.tanggal AS tanggal,
diskusi.diskusi_id as nomor_diskusi
FROM diskusi, komentar
WHERE diskusi.diskusi_status='publish' AND komentar.pilih='1' AND komentar.diskusi_id=diskusi.diskusi_id ORDER BY komentar.id DESC
");
return $data->result_array();
}
i use this code to filter data who data on komentar will be show by id of diskusi.
komentar.diskusi_id=diskusi.diskusi_id
but still not work
and its my controller
$data['setuju']=$this->diskusi->setuju();
code in the view
<div id="netral" class="tab-pane">
<?php
foreach ($netral AS $value) {
echo "<div class='box box-body no-border'>
<div class='row'>
<div class='col-md-2'>
<div class='box-profile'>"; ?>
<img alt='user image' style='margin-top:10px' class='profile-user-img img-responsive img-circle' src='<?php echo img_user_url('user.png'); ?>'>
<?php echo"
<h3><center>$value[nama]</center</h3>
</div>
</div>
<div class='col-md-10'>
<div class='callout callout-danger lead'><span class='pull-right'>".format_tanggal($value['tanggal'])."</span><br>
<p>$value[pesan]</p>
</div>
</div>
</div>
</div>";
}?>
</div><!-- /.tab-pane -->
<div class="box box-danger">
<div class="box-header with-border">
<div class="user-block">
<h3 class="no-margin">Tinggalkan Komentar</h3>
</div><!-- /.user-block -->
<div class="box-tools">
<button data-widget="collapse" class="btn btn-danger btn-sm"><i class="fa fa-minus"></i></button>
</div><!-- /.box-tools -->
</div>
<div class="box-body">
<form method='POST' id='komentar' action='<?php echo baseURL('form_visitors/komentar'); ?>' autocomplete='off' method="post" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="inputName">Name</label>
<div class="col-sm-10">
<input type="hidden" name="diskusi_id" value="<?php echo "$diskusi[id]";?>">
<input type="text" placeholder="Nama" data-original-title="Masukkan Nama" required='required' name="nama" id="inputName" class="form-control">
<input type='hidden' class='form-control' name='url' value='<?php echo current_url() ?>' />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="inputEmail">Email</label>
<div class="col-sm-10">
<input type="email" name="email" data-original-title="Masukkan Email" placeholder="Email" required='required' id="inputEmail" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-10">
<div class="checkbox">
<label>
<input type="radio" name="pilih" value="1"> <i class="fa fa-thumbs-o-up margin-r-5 text-green"> <b>Setuju</b></i>
</label>
<label>
<input type="radio" name="pilih" value="2"> <i class="fa fa-square margin-r-5 text-yellow"> <b>Netral</b></i>
</label>
<label>
<input type="radio" name="pilih" value="3"> <i class="fa fa-thumbs-o-down margin-r-5 text-red"> <b>Tidak Setuju</b></i>
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="inputExperience">Komentar</label>
<div class="col-sm-10">
<textarea placeholder="Komentar" name="pesan" id="inputExperience" required='required' class="form-control"></textarea>
</div>
</div>
<div class='form-group'>
<label class="col-sm-2 control-label" for="inputExperience"></label>
<div class="col-sm-10">
<div id='recaptcha1'></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-danger" type="submit" id="submit">Submit</button>
<div class="cssload" style="display: none; width: 100px">
<div class="cssload-tube-tunnel"></div>
</div>
</div>
</div>
</form>
</div>
</div>
how can i show comment data according with single post of diskusi who have comment. Thank you very much in advance! sorry for my english.
I can see you are fetching the data from two different tables but you have not used 'JOIN'.
you can try the following query string :
public function setuju(){
$data=$this->CI->db->query("SELECT komentar.id AS id,
komentar.diskusi_id AS id_diskusi,
komentar.pilih AS pilih,
komentar.nama AS nama,
komentar.email AS email,
komentar.pesan AS pesan,
komentar.tanggal AS tanggal,
diskusi.diskusi_id as nomor_diskusi
FROM komentar, diskusi
JOIN diskusi
ON diskusi.diskusi_id=komentar.diskusi_id
WHERE diskusi.diskusi_status='publish' AND komentar.pilih='1' ORDER BY komentar.id DESC
");
return $data->result_array();
}

Date Range in Bootstrap DatePicker

Which bootstrap files need to include and how to implement the bootstrap datepicker?
<script src="~/Scripts/Common/bootstrap-datepicker.js"></script>
<link href="~/Content/datepicker.css" rel="stylesheet" />
this is the code:
<div id="yeadDropdown" class="drpDownMarginAdjust">
<div class='col-md-5'>
<div class="form-group">
<div class='input-group date' id='datetimepicker6'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
<div class='col-md-5'>
<div class="form-group">
<div class='input-group date' id='datetimepicker7'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</div>
</div>
It depends on which datepicker plugin you are using. Because, there are many bootstrap datepickers.
But usually to initiate datepicker you need to execute this javascript code:
$('.datepicker').datepicker();
Before executing this code add "datepicker" class to your inputs, like this:
<input type='text' class="form-control datepicker" />

Resources