添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary

I'm using version 1.6.1 of bootstrap-datepicker. I have the following form field on a JSP page:

<input class="datepicker form-control" type="text" name="day" value="<%=day%>" size="10" onchange="return submit_form(this.form,'day');">

The intent is to allow a new date to be picked, and upon selection to trigger form submission using the 'onchange' event.

I have the following initialization block:

<script>
    $(document).ready(function(){
        $('.datepicker').datepicker({format: 'mm/dd/yyyy', autoclose: 'true', todayBtn: 'true', todayHighlight: 'true', orientation: 'auto top'});
</script>

The issue I'm having is that upon page load, 'submit_form' is called, loading the page again and then 'submit_form' called again, so the page reloads in an infinite loop because it's being submitted in an infinite loop. This does not happen with version 1.4.0 of the library, so I'm inclined to think it's a bug in the new version.

Can anybody confirm that my use of the component is reasonable (correct) and if there is, in fact, a bug in the updated of bootstrap-datepicker?

Just browsing, but instead of the onchange attribute try using the changeDate event:

$(document).ready(function(){
    $('.datepicker').datepicker({
            format: 'mm/dd/yyyy',
            autoclose: 'true',
            todayBtn: 'true',
            todayHighlight: 'true',
            orientation: 'auto top'
        }).on('changeDate', function() {
            // code to submit form here
        });
});

@msct - your recommended solution works; however, it does mean writing more javascript code within the page whenever I want to auto-submit upon date change...before the most recent version all I needed was the 'onchange' approach and a "global" datepicker configuration. Your solution allows me to upgrade this component, so thank you for pointing this out.