预输入编辑无效时,设定输入为假 [英] Set input invalid when typeahead-editable is false

查看:92
本文介绍了预输入编辑无效时,设定输入为假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用预输入的UI bootstrap部分,我想迫使选择来验证我的形式。
是否有可能将其配置为设置输入无效时,预输入编辑的设置为false,并且用户进入一个坏的价值,或者我应该写这样的指令(但如何?)?

感谢

更新2013年8月9日9:54:
你觉得下面的解决方案是什么:


VAR formValidatorsModule = angular.module('app.validator.formValidator',[]);formValidatorsModule.directive('typeaheadForceSelection',函数(){
    返回{
        要求:'ngModel',
        链接:功能(范围,榆树,ATTRS,CTRL){
            Ctrl键。$ parsers.push(功能(viewValue){
                如果(viewValue ==未定义){
                    CTRL $ setValidity('typeaheadForceSelection',虚假)。
                }其他{
                    CTRL $ setValidity('typeaheadForceSelection',真)。
                }
                返回viewValue;
            });
        }
    };
});


解决方案

从的预输入指令http://angular-ui.github.io /bootstrap/\">http://angular-ui.github.io/bootstrap/ 已经用于限制输入比赛支持(换言之,人们可以绑定到可用的唯一值建模为在预输入弹出匹配)。你可以通过简单的设置做到这一点预输入编辑=假属性。

请注意,设置该属性为将的的prevent人打字,无效的值。它只是将确保一个相应的输入被标记为无效,并且所提供的数值不绑定到模型。

I'm using typeahead's UI Bootstrap component and I want to force selection to validate my form. Is it possible to configure it to set the input invalid when 'typeahead-editable' is set to false and user enters a "bad" value or I should write a directive for this (but how ?)?

Thanks

UPDATE 2013-08-09 9:54: What do you think of the following solution :

var formValidatorsModule = angular.module('app.validator.formValidator', []);

formValidatorsModule.directive('typeaheadForceSelection', function() {
    return {
        require : 'ngModel',
        link : function(scope, elm, attrs, ctrl) {
            ctrl.$parsers.push(function(viewValue) {
                if (viewValue == undefined) {
                    ctrl.$setValidity('typeaheadForceSelection', false);
                } else {
                    ctrl.$setValidity('typeaheadForceSelection', true);
                }
                return viewValue;
            });
        }
    };
});

解决方案

The typeahead directive from http://angular-ui.github.io/bootstrap/ has already support for limiting inputs to matches (in other words, people can bind to model only values available as matches in the typeahead popup). You can do this by simply setting typeahead-editable='false' attribute.

Please note that setting this attribute to false will not prevent people from typing-in invalid values. It will just make sure that a corresponding input is marked as invalid and a provided value is not bound to the model.

这篇关于预输入编辑无效时,设定输入为假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆