如何将 max-length 属性添加到 Angular-xeditable?
How to add max-length attribute to Angular-xeditable?
<span editable-text="contact.phoneNumber" maxlength="5" e-name="phoneNumber" e-form="contactForm" >
{{ contact.phoneNumber || '' }}
</span>
我在 span 中使用了该指令,当我们单击按钮编辑联系电话号码时,它会在 运行 时生成输入框。我想为此输入框添加最大长度。有什么建议吗?
创建指令限制值:
app.directive("limitTo", [function() {
return {
restrict: "A",
link: function(scope, elem, attrs) {
var limit = parseInt(attrs.limitTo);
angular.element(elem).on("keydown", function() {
if (this.value.length == limit) return false;
});
}
} }]);
<input limit-to="4" type="number" class="form-control input-lg" ng-model="search.main" placeholder="enter first 4 digits: 09XX">
希望对您有所帮助
你可以使用
e-maxlength e-minlength
如果你看到 documentacion ,在 e 属性上你有这个:
Attributes defined with e-* prefix automatically transfered from original element to control.
<span editable-text="contact.phoneNumber" maxlength="5" e-name="phoneNumber" e-form="contactForm" >
{{ contact.phoneNumber || '' }}
</span>
我在 span 中使用了该指令,当我们单击按钮编辑联系电话号码时,它会在 运行 时生成输入框。我想为此输入框添加最大长度。有什么建议吗?
创建指令限制值:
app.directive("limitTo", [function() {
return {
restrict: "A",
link: function(scope, elem, attrs) {
var limit = parseInt(attrs.limitTo);
angular.element(elem).on("keydown", function() {
if (this.value.length == limit) return false;
});
}
} }]);
<input limit-to="4" type="number" class="form-control input-lg" ng-model="search.main" placeholder="enter first 4 digits: 09XX">
希望对您有所帮助
你可以使用
e-maxlength e-minlength
如果你看到 documentacion ,在 e 属性上你有这个:
Attributes defined with e-* prefix automatically transfered from original element to control.