Skip to content

Commit c294b39

Browse files
committed
logbon72#118 clear button for edit-input
1 parent ab42de3 commit c294b39

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

css/material-datetimepicker.css

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,4 +394,18 @@ md-dialog.dtp {
394394

395395
.dtp-btn-today, .dtp-btn-ok, .dtp-btn-cancel {
396396
min-width: 70px;
397-
}
397+
}
398+
399+
.dtp-clear {
400+
position: absolute;
401+
top: 0;
402+
right: -10px;
403+
}
404+
405+
/* Remove IE clear button */
406+
.dtp-no-msclear::-ms-clear {
407+
display: none;
408+
width : 0;
409+
height: 0;
410+
}
411+

js/angular-material-datetimepicker.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@
141141
return default_params;
142142
};
143143
})
144-
.directive('mdcDatetimePicker', ['$mdDialog', '$timeout',
145-
function ($mdDialog, $timeout) {
144+
.directive('mdcDatetimePicker', ['$mdDialog', '$timeout', '$compile',
145+
function ($mdDialog, $timeout, $compile) {
146146

147147
return {
148148
restrict: 'A',
@@ -216,7 +216,6 @@
216216

217217
}
218218

219-
//@TODO custom event to trigger input
220219
if (!scope.editInput) {
221220
element.on('focus', function (e) {
222221
e.preventDefault();
@@ -266,6 +265,17 @@
266265
})
267266
;
268267
});
268+
} else {
269+
element.addClass('dtp-no-msclear');
270+
element.after($compile('<md-button class="md-icon-button dtp-clear" ng-click="clear()">&#x2715;</md-button>')(scope));
271+
272+
scope.clear = function() {
273+
ngModel.$setViewValue(null);
274+
ngModel.$render();
275+
$timeout(function() {
276+
element[0].focus();
277+
}, 0, false);
278+
};
269279
}
270280
}
271281
};

0 commit comments

Comments
 (0)