diff --git a/src/main/webapp/resources/xit/common_util.js b/src/main/webapp/resources/xit/common_util.js index de459b8..25aa10c 100644 --- a/src/main/webapp/resources/xit/common_util.js +++ b/src/main/webapp/resources/xit/common_util.js @@ -194,7 +194,27 @@ $(document).ready(function () { * @returns {boolean} */ function isEmpty(value) { - var isEmptyObject = function(a) { + + if (value === null || value === undefined) { + return true; + } + + if (typeof value === 'string' && value.trim() === '') { + return true; + } + + if (Array.isArray(value) && value.length === 0) { + return true; + } + + if (typeof value === 'object' && Object.keys(value).length === 0) { + return true; + } + return false; + + /* + 기존소스 주석. 0 true 가 이닌 false 처리 + var isEmptyObject = function(a) { if(typeof a.length === 'undefined') { // it's an Object, not an Array var hasNonempty = Object.keys(a).some(function nonEmpty(element) { return !isEmpty(a[element]); @@ -208,6 +228,7 @@ function isEmpty(value) { }); }; return(value == false || typeof value === 'undefined' || value == null || (typeof value === 'object' && isEmptyObject(value))); + */ } /** * null 이나 빈값을 기본값으로 변경 diff --git a/src/main/webapp/resources/xit/xit-validation.js b/src/main/webapp/resources/xit/xit-validation.js index df1be1f..87a517f 100644 --- a/src/main/webapp/resources/xit/xit-validation.js +++ b/src/main/webapp/resources/xit/xit-validation.js @@ -130,6 +130,7 @@ function validateByAttribute(element) { switch (type) { case 'required': if (isEmpty(value)) { + console.log(value, isEmpty(value)); isValid = false; errorMessage = '필수 입력 항목입니다.'; } @@ -347,7 +348,7 @@ function getByteLength(str) { } /** - * 값이 비어있는지 확인합니다. + * 값이 비어있는지 확인합니다., common_util.js 에 있는거 사용 * * @param {*} value - 검증할 값 * @returns {boolean} - 값이 비어있으면 true, 그렇지 않으면 false @@ -368,7 +369,6 @@ function isEmpty(value) { if (typeof value === 'object' && Object.keys(value).length === 0) { return true; } - return false; }