MCDatepicker icon indicating copy to clipboard operation
MCDatepicker copied to clipboard

Help on display select date in DIV on Modal

Open stkol76 opened this issue 2 years ago • 6 comments

Hi @mikecoj

I hope you can help me .. I need to display the Selected Date of the MC Datepicker into a DIV, and I have tried multiple jQuery and native JavaScript ways to do so, that in my lap works with jQuery datepickers and normal input fields, but fails with the MC Datepicker

i.e

<input type="text" name="EndDate" id="EndDate" style="width: 140px;" class="form-control border-left-0" placeholder="vælg slut dato.." onselect="toggle2()"">

<div id="ConfirmEndDateHolder"></div>

<script>
var SelectEndDate = $('#EndDate');
function EndDatePlaceholder() {
    $("#ConfirmEndDateHolder").html(SelectEndDate.val());
}
</script>

My hope is that the date i.e 17-06-2022 could be displayed as Torsdag d. 17 Juni 2022 (Translated to English : Thursday 17th June 2022)

I hope you can help me out :-)

Best Regards Stig

stkol76 avatar Jun 16 '22 23:06 stkol76

Have you used the dateFormat, customWeekDays, customMonths when you've set the options of your datepicker (see here MCDatepiker Documentation?

You should then be able to use the getFormattedDate() function to set the contents of your div (see here MCDatepicker Documentation.

I hope this helps

ashenshugarRET avatar Jun 17 '22 06:06 ashenshugarRET

Hi @ashenshugarRET :-)

Great that helps on the format of the output, but my first hurdle is to get it to display in the DIV at all .. can you point me on how to do that? :-)

stkol76 avatar Jun 17 '22 06:06 stkol76

Assuming you declared your datepicker like this: const picker = MCDatepicker.create({ disableWeekends: true });

That is you can call the datepicker with picker, you should then be able to use the following to set the contents of your div to the formatted date: document.getElementById("ConfirmEndDateHolder").value = picker.getFormatedDate();

ashenshugarRET avatar Jun 17 '22 06:06 ashenshugarRET

If the above doesn't work try: document.getElementById("ConfirmEndDateHolder").innerHTML = picker.getFormatedDate();

ashenshugarRET avatar Jun 17 '22 12:06 ashenshugarRET

Thank you for your great help @ashenshugarRET, I have it now working after some playing around with different methods, and the final solution was a combo of your tips and using Moment JS :

$( document ).ready(function() {
  $('#BtnProceed').click(function() {

        var TheEndDate = document.getElementById("ConfirmEndDateHolder").value = EndCalendar.getFullDate();

        m = moment(new Date(TheEndDate)).format("dddd, Do MMMM YYYY");

        $("#ConfirmEndDateHolder").text(m);

  });    
});

stkol76 avatar Jun 17 '22 13:06 stkol76

If your problem is solved, could you close the issue?

ashenshugarRET avatar Jun 21 '22 18:06 ashenshugarRET