0

I am using Bootstrap 3 Datepicker. And when I select the start date, then in end date automatically gets filled in another field to the next date. I just cannot figure out why I am getting it. The code is working fine in Firefox and Chrome but in Safari console, it's giving me an error. Any idea why I might get.

SyntaxError: Expected an identifier but found '[' instead

The Code:

<div class="row">
    <div class="col-xs-5 search_date">
        <label>{{lang('start_date')}}</label>
        <input type='text' name="start_date" id="start_date"  value="<?php echo @$start_date; ?>" required=""/>
        <span class="text-danger"><?php echo @$error['start_date']; ?></span>
        <input style="border:0;" type="text" name="start_time" id="start_time" required=""  class="" value="<?php echo @$start_time; ?>"  />
        <span class="text-danger"><?php echo @$error['start_time']; ?></span>
    </div>
    <div class="col-xs-2 p-t40">
        <img src="{{ asset('images/web/arrow-right.png') }}" class="m-t40">
    </div>
    <div class="col-xs-5 search_date">
        <label>{{lang('end_date')}}</label>
        <input type="text" name="end_date" id="end_date" required="" class="" value="<?php echo @$end_date; ?>" />
        <span class="text-danger"><?php echo @$error['end_date']; ?></span>
        <input style="border:0;" type="text" name="end_time" id="end_time" required=""  value="<?php echo @$end_time; ?>"  />
        <span class="text-danger"><?php echo @$error['end_time']; ?></span>
    </div>
</div>

<script>
    $(function () {
        $('#start_date').datetimepicker({
            format: 'DD-MM-YYYY',
            minDate: moment().add(1, 'days'),
        });
    <?php if (isset($start_date)) { ?>
        $('#start_date').val('<?php echo @$start_date; ?>');
    <?php } ?>
        $('#end_date').datetimepicker({
            format: 'DD-MM-YYYY',
            minDate: moment().add(2, 'days'),
        });
    <?php if (isset($end_date)) { ?>
        $('#end_date').val('<?php echo @$end_date; ?>');
    <?php } ?>
        $("#start_date").on("dp.change", function (e) {
            const[day, month, year] = $('#start_date').val().split("-");
            var strt_dt = new Date(year + "-" + month + "-" + day);
            var ultimate = strt_dt.setDate(strt_dt.getDate() + 1);
            var d = new Date(ultimate);
            $('#end_date').data("DateTimePicker").minDate(d);
        });

        $('#end_time').datetimepicker({
            format: 'H:m',
        });

        $('#start_time').datetimepicker({
            format: 'H:m',
        });

    });
    $(document).on('change', '#start_date, #end_date', function () {
        $('#end_date').attr('min', $('#start_date').val());
        $('#start_date').attr('max', $('#end_date').val());
    });
</script>

I am getting another problem only on Safari console which is : SyntaxError: Expected token ')'

And here is my following code:

<script>
    function alertbox(heading = null, meassage = null) {
        if (heading != null && meassage != null) {
            $('#alert_heading').html(heading);
            $('#alert_message').html(meassage);
            $('#alert_model').modal('show');
        }
    }
</script>
Robert
  • 2,407
  • 1
  • 24
  • 35
Irfan
  • 77
  • 10

2 Answers2

0

change from

 function alertbox(heading = null, meassage = null) {
                        if (heading != null && meassage != null) {
                            $('#alert_heading').html(heading);
                            $('#alert_message').html(meassage);
                            $('#alert_model').modal('show');
                    }
                    }

to

 function alertbox(heading, meassage) 
 {
    if(heading  === undefined)
    {
            heading  = null;
    }
    if(meassage === undefined)
    {
        meassage  = null;
    }
   if (heading != null && meassage != null) 
    {
       $('#alert_heading').html(heading);
       $('#alert_message').html(meassage);
       $('#alert_model').modal('show');
    }
 }

Safari not allow the assignment like this in function,

SF..MJ
  • 862
  • 8
  • 19
  • Thanks MJ it worked. Can you please look my first problem too – Irfan Mar 08 '18 at 11:30
  • @Lalit Onclick just copied my answer and Irfan YOU knew.. you select my answer first and after removing that you checkd lalits ans why? – SF..MJ Mar 08 '18 at 11:58
  • 1
    I appreciate your efforts. But Lalit gave me complete solution of my problem and you gave partial answer. Please look at the comments too. But I thanking you again for your all efforts. – Irfan Mar 08 '18 at 12:56
0

Default parameters from ES2015 are not yet supported in Safari. parameters

you can use the following ES5 to let this working

replace you js function with given below to keep this working.

 function alertbox(heading, meassage) 
 {
    if(heading  === undefined)
    {
            heading  = null;
    }
    if(meassage === undefined)
    {
        meassage  = null;
    }
   if (heading != null && meassage != null) 
    {
       $('#alert_heading').html(heading);
       $('#alert_message').html(meassage);
       $('#alert_model').modal('show');
    }
 }
Lalit Mohan
  • 464
  • 3
  • 16