index.rst 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. bootstrap-datepicker
  2. ====================
  3. Bootstrap-datepicker provides a flexible datepicker widget in the Bootstrap style.
  4. .. figure:: _static/screenshots/demo_head.png
  5. :align: center
  6. Versions are incremented according to `semver <http://semver.org/>`_.
  7. `Online Demo <https://eternicode.github.io/bootstrap-datepicker/>`_
  8. Requirements
  9. ------------
  10. * `Bootstrap`_ 2.0.4+
  11. * `jQuery`_ 1.7.1+
  12. .. _Bootstrap: https://getbootstrap.com/
  13. .. _jQuery: https://jquery.com/
  14. These are the specific versions bootstrap-datepicker is tested against (``js`` files) and built against (``css`` files). Use other versions at your own risk.
  15. Dependencies
  16. ------------
  17. Requires bootstrap's dropdown component (``dropdowns.less``) for some styles, and bootstrap's sprites (``sprites.less`` and associated images) for arrows.
  18. A standalone .css file (including necessary dropdown styles and alternative, text-based arrows) can be generated by running ``build/build_standalone.less`` through the ``lessc`` compiler::
  19. $ lessc build/build_standalone.less datepicker.css
  20. Usage
  21. -----
  22. Call the datepicker via javascript::
  23. $('.datepicker').datepicker();
  24. Data API
  25. ^^^^^^^^
  26. As with bootstrap's own plugins, datepicker provides a data-api that can be used to instantiate datepickers without the need for custom javascript. For most datepickers, simply set ``data-provide="datepicker"`` on the element you want to initialize, and it will be intialized lazily, in true bootstrap fashion. For inline datepickers, use ``data-provide="datepicker-inline"``; these will be immediately initialized on page load, and cannot be lazily loaded.
  27. .. code-block:: html
  28. <input data-provide="datepicker">
  29. Markup with component
  30. .. code-block:: html
  31. <div class="input-group date" data-provide="datepicker">
  32. <input type="text" class="form-control">
  33. <div class="input-group-addon">
  34. <span class="glyphicon glyphicon-th"></span>
  35. </div>
  36. </div>
  37. You can disable datepicker's data-api in the same way as you would disable other bootstrap plugins::
  38. $(document).off('.datepicker.data-api');
  39. Configuration
  40. ^^^^^^^^^^^^^
  41. :doc:`options` are passed to the ``datepicker`` function via an options hash at instantiation::
  42. $('.datepicker').datepicker({
  43. format: 'mm/dd/yyyy',
  44. startDate: '-3d'
  45. });
  46. Most options may be provided as data-attributes on the target element:
  47. .. code-block:: html
  48. <input class="datepicker" data-date-format="mm/dd/yyyy">
  49. ::
  50. $('.datepicker').datepicker({
  51. startDate: '-3d'
  52. });
  53. Defaults for all options can be modified directly by changing values in the ``$.fn.datepicker.defaults`` hash::
  54. $.fn.datepicker.defaults.format = "mm/dd/yyyy";
  55. $('.datepicker').datepicker({
  56. startDate: '-3d'
  57. });
  58. Stylesheets
  59. ^^^^^^^^^^^
  60. There are a few different stylesheets included in the library. This is an overview of what each file is to be used for:
  61. :code:`bootstrap-datepicker.css` gives legacy support for twitter bootstrap v2, :code:`bootstrap-datepicker3.css` is used for twitter bootstrap v3 support
  62. and :code:`bootstrap-datepicker.standalone.css` can be used to include the datepicker without depending on the twitter bootstrap library.
  63. No Conflict mode
  64. ^^^^^^^^^^^^^^^^
  65. ``$.fn.datepicker.noConflict`` provides a way to avoid conflict with other jQuery datepicker plugins::
  66. var datepicker = $.fn.datepicker.noConflict(); // return $.fn.datepicker to previously assigned value
  67. $.fn.bootstrapDP = datepicker; // give $().bootstrapDP the bootstrap-datepicker functionality
  68. Table of Contents
  69. -----------------
  70. .. toctree::
  71. markup
  72. options
  73. methods
  74. events
  75. keyboard
  76. i18n