How to add DatePicker at JHipster UI

孤者浪人 提交于 2019-12-01 09:12:36

I added it to my project using WebJars:

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>bootstrap-datepicker</artifactId>
    <version>1.3.1</version>
</dependency>

Then I use class="date" on my date fields and use the following HTML/JS to initialize the field.

<link rel="stylesheet" type="text/css" media="all" href="/webjars/bootstrap-datepicker/1.3.1/css/datepicker.css" />
<script type="text/javascript" src="/webjars/bootstrap-datepicker/1.3.1/js/bootstrap-datepicker.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('.date').datepicker({format: "mm/dd/yyyy", weekStart: "0"});
    });
</script>

To do it with Bower, I used the following steps:

In bower.json, add bootstrap-datepicker as a dependency. I added it just after bootstrap-sass.

"bootstrap-datepicker": "1.3.1"

Then run:

bower install

In src/main/webapp/index.html, add links to the CSS and JS files:

<head>
    ...
    <link rel="stylesheet" src="bower_components/bootstrap-datepicker/css/datepicker.css">
    ...
</head>

<script src="bower_components/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>

To prove it works, I added a "birthdate" field to register.html. Note the data-provide attribute triggers the popup calendar.

    <div class="form-group">
        <label for="birthdate">Birth Date</label>
        <input type="text" class="form-control" name="birthdate" data-provide="datepicker">
    </div>

An alternative to this is to use AngularJS Bootstrap module which provides several other widgets apart from Datepicker.

bower install angular-bootstrap

Full Documentation here and here

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