javascript - bootstrap-datetimepicker: display value of input -
how can persuade datetimepicker display value in input text field @ initial pageload?
in case value attribute of datepicker text-input set, field displayed blank. therefore i've tried set 'data-date-defaultdate' attribute @ initial pageload text field´s still blank. after reload value displayed expected.
the form (excerpt):
<form name="news" method="post" class="form-horizontal"> <div class="form-group"> <label class="col-sm-2 control-label required" for="news_validfrom">start time</label> <div class="col-sm-8 col-md-6"> <div class="input-group date datetime-picker" id="datetime1"> <input type="text" id="news_validfrom" name="news[validfrom]" required="required" class="form-control" value="2016-07-08t00:00:00+02:00" /> <span class="input-group-addon"> <span class="fa fa-calendar"></span> </span> </div> </div> </div> <div class="form-group"> <label class="col-sm-2 control-label required" for="news_validto">end date</label> <div class="col-sm-8 col-md-6"> <div class="input-group date date-picker" id="datetime2"> <input type="text" id="news_validto" name="news[validto]" required="required" class="form-control" value="2016-06-22t00:00:00+02:00" /> <span class="input-group-addon"> <span class="fa fa-calendar"></span> </span> </div> </div> </div> // [...] </form>
the script:
$(function () { $('#datetime1') .attr('data-date-defaultdate', $('#datetime1 input').attr('value')) .datetimepicker({ format: 'dd mmm yyyy hh:mm', defaultdate: $('#datetime1 input').attr('value'), viewdate: 'true' }); $('#datetime2') .attr('data-date-defaultdate', $('#datetime2 input').attr('value')) .datetimepicker({ format: 'dd mmm yyyy hh:mm', defaultdate: $('#datetime2 input').attr('value') }); });
any ideas how make work?
chnage to:
$(function () { $('#datetime1') .attr('data-date-defaultdate', $('#datetime1 input').val()) .datetimepicker({ format: 'dd mmm yyyy hh:mm', defaultdate: $('#datetime1 input').val(s), viewdate: 'true' }); $('#datetime2') .attr('data-date-defaultdate', $('#datetime2 input').val()) .datetimepicker({ format: 'dd mmm yyyy hh:mm', defaultdate: $('#datetime2 input').val() }); });
Comments
Post a Comment