mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
#18739620 길이 체크가 정상적으로 되지 않던 버그 수정(again)
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7324 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
fdc4e27c41
commit
53286dda4b
2 changed files with 111 additions and 2 deletions
109
common/js/unittest/unittest_validator.html
Normal file
109
common/js/unittest/unittest_validator.html
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
|
||||
<title>JSSpec results</title>
|
||||
<link rel="stylesheet" type="text/css" href="css/JSSpec.css" />
|
||||
<script type="text/javascript" src="JSSpec/JSSpec.js"></script>
|
||||
<script type="text/javascript" src="JSSpec/diff_match_patch.js"></script>
|
||||
<script type="text/javascript" src="../jquery.js"></script>
|
||||
<script type="text/javascript" src="../js_app.js"></script>
|
||||
<script type="text/javascript" src="../xml_js_filter.js"></script>
|
||||
<script type="text/javascript">// <![CDATA[
|
||||
var v, f, t, last_alert='';
|
||||
var validate, set_filter, set_value;
|
||||
describe('Validator', {
|
||||
'before' : function() {
|
||||
v = xe.getApp('Validator')[0];
|
||||
f = $('#form1');
|
||||
t = f[0].elements['text'];
|
||||
|
||||
validate = function(){ return v.cast('VALIDATE', [f[0]]); };
|
||||
set_filter = function(filter_name){ f[0]._filter.value = filter_name };
|
||||
set_value = function(val){ t.value = val };
|
||||
|
||||
var silent = xe.createPlugin('silent', {
|
||||
API_BEFORE_SHOW_ALERT : function(sender, params) { last_alert=params[1]; return false; }
|
||||
});
|
||||
v.registerPlugin(new silent);
|
||||
},
|
||||
'should be true with no filter' : function() {
|
||||
// no filter
|
||||
set_filter('');
|
||||
value_of(validate()).should_be_true();
|
||||
},
|
||||
'should check required feild' : function() {
|
||||
v.cast('ADD_FILTER', ['required', {
|
||||
'text' : {required:true}
|
||||
}]);
|
||||
set_filter('required');
|
||||
|
||||
set_value('');
|
||||
value_of(validate()).should_be_false();
|
||||
|
||||
set_value('1');
|
||||
value_of(validate()).should_be_true();
|
||||
},
|
||||
'validate email' : function() {
|
||||
v.cast('ADD_FILTER', ['email', {
|
||||
'text' : {required:true, rule:'email'}
|
||||
}]);
|
||||
set_filter('email');
|
||||
|
||||
set_value('not_email');
|
||||
value_of(validate()).should_be_false();
|
||||
|
||||
set_value('email@mail.com');
|
||||
value_of(validate()).should_be_true();
|
||||
},
|
||||
'validate with length' : function() {
|
||||
v.cast('ADD_FILTER', ['minlen', {
|
||||
'text' : {required:true, minlen:5}
|
||||
}]);
|
||||
v.cast('ADD_FILTER', ['maxlen', {
|
||||
'text' : {required:true, maxlen:10}
|
||||
}]);
|
||||
v.cast('ADD_FILTER', ['minmaxlen', {
|
||||
'text' : {required:true, minlen:5, maxlen:10}
|
||||
}]);
|
||||
|
||||
set_filter('minlen');
|
||||
|
||||
set_value('1');
|
||||
value_of(validate()).should_be_false();
|
||||
|
||||
set_value('12345');
|
||||
value_of(validate()).should_be_true();
|
||||
|
||||
set_filter('maxlen');
|
||||
|
||||
set_value('12345678901');
|
||||
value_of(validate()).should_be_false();
|
||||
|
||||
set_value('1');
|
||||
value_of(validate()).should_be_true();
|
||||
|
||||
set_filter('minmaxlen');
|
||||
|
||||
set_value('1');
|
||||
value_of(validate()).should_be_false();
|
||||
|
||||
set_value('12345678901');
|
||||
value_of(validate()).should_be_false();
|
||||
|
||||
set_value('12345');
|
||||
value_of(validate()).should_be_true();
|
||||
|
||||
set_value('1234567');
|
||||
value_of(validate()).should_be_true();
|
||||
}
|
||||
})
|
||||
// ]]></script>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1">
|
||||
<input type="hidden" name="_filter" value="" />
|
||||
<input type="hidden" name="text" value="" />
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -104,7 +104,7 @@ var Validator = xe.createApp('Validator', {
|
|||
|
||||
if (this.required && !val) return (result = (!!self.cast('ALERT', [form, name, 'isnull']) && false));
|
||||
if (!this.required && !val) return (result = true);
|
||||
if ((minlen && maxlen) && (val.length < minlen || val.length > maxlen)) return (result = (!!self.cast('ALERT', [form, name, 'outofrange', minlen, maxlen]) && false));
|
||||
if ((minlen && val.length < minlen) || (maxlen && val.length > maxlen)) return (result = (!!self.cast('ALERT', [form, name, 'outofrange', minlen, maxlen]) && false));
|
||||
|
||||
if (this.equalto) {
|
||||
var eq_val = get_value($(form.elements[this.equalto]));
|
||||
|
|
@ -198,7 +198,7 @@ var Validator = xe.createApp('Validator', {
|
|||
var msg = this.cast('GET_MESSAGE', [msg_code]);
|
||||
|
||||
if (msg != msg_code) msg = (msg.indexOf('%s')<0)?(field_msg+msg):(msg.replace('%s',field_msg));
|
||||
if (typeof(minlen)!='undefined' && typeof(maxlen)!='undefined') msg += '('+minlen+'~'+maxlen+')';
|
||||
if (minlen||maxlen) msg += '('+(minlen||'')+'~'+(maxlen||'')+')';
|
||||
|
||||
this.cast('SHOW_ALERT', [msg]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue