From 226da61230bddffe2bb118065313f19d8a706c0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=EC=98=81?= Date: Tue, 9 Sep 2025 17:06:57 +0900 Subject: [PATCH] =?UTF-8?q?isEmpty=20js=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95...=20=EC=B6=94=ED=9B=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=20=ED=95=84=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/webapp/resources/xit/common_util.js | 23 ++++++++++++++++++- .../webapp/resources/xit/xit-validation.js | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) 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; }