change value of a datetimeWidget from JQuery

0

I create a DateTimeField with Django in the following way:

start_date_edited = forms.DateTimeField(label="Fecha inicio", widget=DateTimeWidget(usel10n=True, bootstrap_version=3), required=False)

That creates a field where to enter a date, which works correctly, but I need that from JQuery I can change the value to that datepicker whose id I know.

I've tried with $("#id_start_edit_date").defaultValue = res[0];

$("#id_start_edit_date").val(res[0]);

and several other combinations, the value of res [0] has the following format: "11/02/2018 13:45:25"

If there is any doubt, what I want is to change the value shown in that input through the DOM with Jqery or Javascript.

    
asked by XBoss 11.02.2018 в 22:12
source

1 answer

0

Try passing the date in Year / Month / Day format .val (res [0]); it should work You can split and reorder the positions.

var normalDate = res[0].split(' ');
var dateTimeArr= splittedDate[0].split('/');
var dateParts= dateTimeArr[0].split('/');

$("#id_start_edit_date").val(dateParts[2] + "/" + dateParts[1] + "/" + dateParts[0] + " " + dateTimeArr[1]);
    
answered by 12.02.2018 в 21:42