Can someone explain how to capture the selected date from the inline/embedded version of Eternicode's extended Bootstrape Datepicker - http://eternicode.github.io/bootstrap-datepicker/
<form class="form-date" role="form" action="/'.$ref.'/edit" method="get">
<div class="form-group" id="datepickid">
<div></div>
<input type="hidden" name="dt_due" id="dt_due">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
...
$('#datepickid div').datepicker({
startDate: "+1d",
todayHighlight: true
});
As I'm sure is clear, I want it to write to the hidden input when the date selected changes.
I'm sure i'm missing something obvious, but the other examples write to the input it is linked too, but there seems to be no obvious way the data is output from the inline version.
All help appreciated.
Go to line 1399 and find format: 'mm/dd/yyyy' . Now you can change the date format here.
Syntax: $(". selector"). datepicker( {defaultDate:"+6"} );
Because you're defining the code in the head the body and its contents haven't been loaded yet; so the selector finds no elements to initialize datepicker. If you don't want to use document. ready functionality you could also move the script to the end of the body tag.
Recently I am working in a project that needs to implement some pages using datepicker for more user usability, more specific Bootstrap 3 DatePicker, particulary I think is the best framework I ever found on the internet. While I was developing, I found the same problem you describe, but how I don't know what specific framework you are using, I am describing my solution and my code. Initially, the framework in question is the Bootstrap 3 Datepicker. This answer may not be useful to some users using another frameworks, different from this.
My HTML code:
<div class="form-group form-group-md" align="left">
<label for="inputDataInicial" class="col-form-label">Data Inicial:</label>
<div class="inputDataInicial" name="inputDataInicial" id="inputDataInicial"></div>
</div>
To initialize the datepicker:
$("#inputDataInicial").datetimepicker({
format: 'DD/MM/YYYY',
locale: 'pt-br',
useCurrent: true,
inline: true,
sideBySide: true
}).on('dp.change', function(e){
$('.inputDataInicial').val(e.date.format('YYYYMMDD'));
});
Next, I set the default date using the moment framework - Bootstrap 3 Datepicker uses it:
var currentDate = moment().format('YYYYMMDD');
$('.inputDataInicial').val(currentDate);
$('.inputDataFinal').val(currentDate);
Finally, I implemented a simple button to get the selected date:
$(".btn_relatorio_amap_gerar").unbind("click").on("click",function(e) {
var data_inicial = $(".inputDataInicial").val() + ' 00:00:00';
var data_final = $(".inputDataFinal").val() + ' 23:59:59';
alert(data_inicial + ' - ' + data_final);
});
The result:
I hope that helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With