Clear the value in a datetimepicker field

RagD picture RagD · Aug 21, 2015 · Viewed 33.8k times · Source

I'm sure this is simple and it's my understanding of jquery/javascript that is holding me back - but I can't get this to work.

All I need to do - is - When a button on the screen is clicked, clear some of the input field on the form back to their original values.

This is working fine, for all fields except a datetimepicker field.

Here is the relevant bits of code, that defines the input field :

<div class='form-group' id='START_DATEFormGroup'>    
<label for='START_DATE' class='col-sm-2 control-label' data-toggle='tooltip' data-placement='top' title=''>Start Date</label>
<div class='col-sm-8'>
<div class='input-group date form_date col-sm-3'  data-date-format='dd M yyyy' data-link-field='START_DATE' data-link-format='yyyy-mm-dd'>
<input class='form-control' size='16' type='text'  />
<input type='hidden' id='START_DATE' name='START_DATE' />
<span class='input-group-addon'>
<span class='glyphicon glyphicon-calendar'>
</span> // group-addon
</span> // calendar
</div> // form_date
</div> // col-sm-8
</div> // form-group

I am initializing datetimepicker as follows :

function enableDatepicker(){
    $( document ).ready(function() { 
         $('.form_date').datetimepicker({
            format: 'dd M yyyy',
            minView: 2,
            autoclose: 1,
            })
    });
} 

To clear the input fields down I have :

function clearActionForm(){
     // code here to clear the various input fields to null or their initial values.
     // Need statements to clear the datetimepicker field to null.

}

So, can someone give me the line(s) of code I need to insert into clearActionForm() in order to clear the START_DATE field to null.

Thanks.

Answer

J Santosh picture J Santosh · Aug 21, 2015

use this line $('.form_date').data("DateTimePicker").clear()

Demo