Skip to content

Commit

Permalink
fix datepick input cant update
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ committed Aug 5, 2016
1 parent 5dd8b67 commit 78c0bf4
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
14 changes: 14 additions & 0 deletions bootstrap-components/js/bootstrap-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,19 @@
var _val = null;
_val = $.datepicker.dateToStrng(_date, _format);
_target.val(_val);

// Remove hook function
_instance.getTarget().off("keyup.datepicker");

// Clen up
_instance.remove();
_instance = null;

// trigger event
if(_val != _preVal) {
_target.change();
}

}
_instance = instance;
}
Expand Down Expand Up @@ -550,6 +556,7 @@

refreshInstance($container);

// Popup position update
setTimeout(function () {
var pos = target.offset();
var offset = {
Expand Down Expand Up @@ -734,6 +741,13 @@
$timepicker.hide();
}

// Listen if target input changed
target.on("keyup.datepicker", function () {
var date = $.datepicker.toDate($(this).val(), _format);
dateCurrent = dateShadow = new Date(date.getTime());
draw();
});

// fill date in the view
function draw() {
var _year = dateShadow.getFullYear();
Expand Down
2 changes: 1 addition & 1 deletion bootstrap-components/js/bootstrap-components.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bootstrap-components/js/bootstrap-components.min.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions example/datepicker.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@
</div>
</div>

<div class="clearfix">
<div class="col-lg-3">
<input type="text" id="input_self" class="form-control" data-toggle="datepicker">
</div>
</div>

<div style="height: 2000px;"></div>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zombiej-bootstrap-components",
"version": "1.1.5",
"version": "1.1.6",
"description": "Bootstrap 3 UI components",
"author": "zombieJ",
"repository": {
Expand Down
14 changes: 14 additions & 0 deletions src/datepicker/bootstrap-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@
var _val = null;
_val = $.datepicker.dateToStrng(_date, _format);
_target.val(_val);

// Remove hook function
_instance.getTarget().off("keyup.datepicker");

// Clen up
_instance.remove();
_instance = null;

// trigger event
if(_val != _preVal) {
_target.change();
}

}
_instance = instance;
}
Expand Down Expand Up @@ -334,6 +340,7 @@

refreshInstance($container);

// Popup position update
setTimeout(function () {
var pos = target.offset();
var offset = {
Expand Down Expand Up @@ -518,6 +525,13 @@
$timepicker.hide();
}

// Listen if target input changed
target.on("keyup.datepicker", function () {
var date = $.datepicker.toDate($(this).val(), _format);
dateCurrent = dateShadow = new Date(date.getTime());
draw();
});

// fill date in the view
function draw() {
var _year = dateShadow.getFullYear();
Expand Down

0 comments on commit 78c0bf4

Please sign in to comment.