Datapicker allow invalid dates

拜拜、爱过 提交于 2020-01-05 00:48:13

问题


I need allow date like '99/99/9999' when user doesn't know exact date, how can I implement this?

$('#date').datepicker({
    language: "pt-BR",
    autoclose: true,
    format: 'dd/mm/yyyy',
    todayHighlight: true
})

Using this code, '99/99/9999' is converted to '07/06/9999'.

Here an example: https://jsfiddle.net/bvbtz2re/2/


回答1:


Working fiddle.

You could set the option constrainInput to false :

$('#date').datepicker({
    language: "pt-BR",
    autoclose: true,
    format: 'dd/mm/yyyy',
    todayHighlight: true,
    constrainInput: false 
})

Hope this helps.




回答2:


You can use forceParse option setting its value to false. As the documentation says:

Whether or not to force parsing of the input value when the picker is closed. That is, when an invalid date is left in the input field by the user, the picker will forcibly parse that value, and set the input’s value to the new, valid date, conforming to the given format.

Here a live example:

$('input.datum').datepicker({
  format: 'dd.mm.yyyy',
  language: 'de',
  weekStart: 1,
  autoclose: true,
  assumeNearbyYear: true,
  forceParse: false
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker3.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/locales/bootstrap-datepicker.de.min.js"></script>

<form action="#" method="post">
    <label>Date:</label>
    <input class="datum" type="text" name="vondatum" required>
    <input type="submit" value="save">
</form>


来源:https://stackoverflow.com/questions/41014423/datapicker-allow-invalid-dates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!