4
votes

I'm using two datepickers/html textboxfors to get dates and set min/max for each date picker based on the other. The issue is, when I run the on changeDate function for the datepicker, I get a regex error that causes a stack overflow:

Uncaught SyntaxError: Invalid regular expression: /^date/: Stack overflow at bootstrap-datepicker.js:1328

<script type="text/javascript">
$(document).ready(function() {
    $(".date").datepicker({ autoclose: true })
        .on("changeDate", function() {
            var start = $("#startDate").datepicker("getDate");
            var end = $("#endDate").datepicker("getDate");
            $("#startDate").datepicker('setEndDate', end);
            $("#endDate").datepicker('setStartDate', start);
    });

});
</script>

Has anyone had this issue? This is the code where the error is:

for (var key in data) is the line

function opts_from_el(el, prefix){
    // Derive options from element data-attrs
    var data = $(el).data(),
        out = {}, inkey,
        replace = new RegExp('^' + prefix.toLowerCase() + '([A-Z])');
    prefix = new RegExp('^' + prefix.toLowerCase());
    function re_lower(_,a){
        return a.toLowerCase();
    }
    for (var key in data)
        if (prefix.test(key)){
            inkey = key.replace(replace, re_lower);
            out[inkey] = data[key];
        }
    return out;
}
1
I didn't find any regex in your code. - Avinash Raj
I didn't write any regex. That's why I don't understand why I'm getting a regex error. - paulina
check the line number, 1328 on datepicker.js - Avinash Raj
post the above code in your question. - Avinash Raj
This fiddle ( using your code ) seems to do what you want without errors: jsfiddle.net/6hf7byx2/1 - trevor

1 Answers

1
votes

Using on change instead of on changeDate solved the issue.