Since my form has no labels, I would like to be able to use a different placeholder with Angular and Angular-UI-Utils-Mask:
由于我的表单没有标签,我希望能够使用与Angular和Angular-UI-Utils-Mask不同的占位符:
<div ng-controller="myController">
<input type="text"
ng-model="date"
ui-mask="99/99/9999"
placeholder="Birth Date"/>
</div>
Using jquery-inputmask
it works like a charm, but I had too many problems to make it work with Angular so I'm now trying to go Angular way, but Angular shows my input as:
使用jquery-inputmask它就像一个魅力,但我有太多的问题使它与Angular一起使用所以我现在尝试去Angular方式,但是Angular将我的输入显示为:
Bi/th/Date
Here's a fiddle to show it: http://jsfiddle.net/XS4R6/
这是一个显示它的小提琴:http://jsfiddle.net/XS4R6/
I also saw some people talking about ´ui-mask-placeholder´, but it does nothing.
我也看到一些人在谈论'u-mask-placeholder',但它什么也没做。
Is there a way to accomplish this?
有办法实现这个目标吗?
EDIT
To clarify, I think it's just fine to use just placeholders
since you also use titles
(hint) so people always know what are they supposed to type in those inputs:
为了澄清,我认为只使用占位符就好了,因为你也使用了标题(提示),所以人们总是知道他们应该在这些输入中键入什么:
The input showing __.___.___
is the one I'm using Angular UI Mask.
显示__.___.___的输入是我正在使用Angular UI Mask的输入。
JQuery Inputmask works very fine, since it shows the 'name' placeholder and as soon as I mouse over or click the input it shows the mask.
JQuery Inputmask工作得非常好,因为它显示了'name'占位符,只要我鼠标悬停或单击输入它就会显示掩码。
1 个解决方案
#1
1
I'm thinking you can use another tag to simulate placeholder, maybe the code here is not very good, but I just provide another thought.
我想你可以使用另一个标签来模拟占位符,也许这里的代码不是很好,但我只是提供了另一个想法。
app.directive("myPlaceholder", ['$compile', function($compile){
return {
restrict: 'A',
link: function(scope, elem, attr) {
attr.$observe('myPlaceholder', initialize);
var mask = '__/__/____';
function initialize(value) {
// label is not clickable in IE, that's the reason why we use span tag
var fakePlaceholder = angular.element('<span class="placeholder">' + value + '</span>');
// click placeholder to focus the input
fakePlaceholder.on('click', function(){
elem.focus();
});
elem.before(fakePlaceholder);
$compile(fakePlaceholder)(scope);
elem.on('focus', function() {
fakePlaceholder.hide();
}).on('blur', function() {
if (elem.val() === mask) {
fakePlaceholder.show();
}
});
}
}
};
}]);
demo on http://jsfiddle.net/XS4R6/19/ (jQuery required)
http://jsfiddle.net/XS4R6/19/上的演示(需要jQuery)
#1
1
I'm thinking you can use another tag to simulate placeholder, maybe the code here is not very good, but I just provide another thought.
我想你可以使用另一个标签来模拟占位符,也许这里的代码不是很好,但我只是提供了另一个想法。
app.directive("myPlaceholder", ['$compile', function($compile){
return {
restrict: 'A',
link: function(scope, elem, attr) {
attr.$observe('myPlaceholder', initialize);
var mask = '__/__/____';
function initialize(value) {
// label is not clickable in IE, that's the reason why we use span tag
var fakePlaceholder = angular.element('<span class="placeholder">' + value + '</span>');
// click placeholder to focus the input
fakePlaceholder.on('click', function(){
elem.focus();
});
elem.before(fakePlaceholder);
$compile(fakePlaceholder)(scope);
elem.on('focus', function() {
fakePlaceholder.hide();
}).on('blur', function() {
if (elem.val() === mask) {
fakePlaceholder.show();
}
});
}
}
};
}]);
demo on http://jsfiddle.net/XS4R6/19/ (jQuery required)
http://jsfiddle.net/XS4R6/19/上的演示(需要jQuery)