대댓글 내용없을때 입력 안되게

This commit is contained in:
nevermoregb 2025-02-28 13:59:49 +09:00
parent 08dabf4191
commit 64cb7e30c1
2 changed files with 60 additions and 52 deletions

View File

@ -73,6 +73,14 @@ const common = {
seconds: zeroFormat(date.getSeconds()),
};
},
isNotEmpty(obj) {
if (obj === null || obj === undefined) return false;
if (typeof obj === 'string' && obj.trim() === '') return false;
if ((Array.isArray(obj) || obj === Object(obj)) && Object.keys(obj).length === 0) return false;
return true;
},
};
export default {

View File

@ -11,13 +11,9 @@
</div> -->
<!-- 텍스트박스 -->
<div class="w-100">
<textarea
class="form-control"
placeholder="댓글 달기"
rows="3"
v-model="comment"
></textarea>
<textarea class="form-control" placeholder="댓글 달기" rows="3" v-model="comment"></textarea>
<span v-if="commentAlert" class="invalid-feedback d-block text-start ms-2">{{ commentAlert }}</span>
<span v-else class="invalid-feedback d-block text-start ms-2">{{ textAlert }}</span>
</div>
</div>
@ -26,12 +22,7 @@
<div class="d-flex flex-wrap align-items-center">
<!-- 익명 체크박스 (익명게시판일 경우에만)-->
<div v-if="unknown" class="form-check form-check-inline mb-0 me-4">
<input
class="form-check-input"
type="checkbox"
id="inlineCheckbox1"
v-model="isCheck"
/>
<input class="form-check-input" type="checkbox" id="inlineCheckbox1" v-model="isCheck" />
<label class="form-check-label" for="inlineCheckbox1">익명</label>
</div>
@ -59,7 +50,7 @@
</template>
<script setup>
import { ref, defineEmits, defineProps, computed, watch } from 'vue';
import { ref, defineEmits, defineProps, computed, watch, inject } from 'vue';
import SaveBtn from '../button/SaveBtn.vue';
const props = defineProps({
@ -69,25 +60,33 @@ const props = defineProps({
},
parentId: {
type: Number,
default: 0
default: 0,
},
passwordAlert: {
type: String,
default: ''
default: '',
},
commentAlert: {
type: String,
default: ''
}
default: '',
},
});
const $common = inject('common');
const comment = ref('');
const password = ref('');
const isCheck = ref(props.unknown);
const textAlert = ref('');
const emit = defineEmits(['submitComment']);
const LOCBRDTYP = isCheck.value ? '300102' : null;
function handleCommentSubmit() {
if (!$common.isNotEmpty(comment.value)) {
textAlert.value = '댓글을 입력하세요';
return false;
} else {
textAlert.value = '';
}
emit('submitComment', {
comment: comment.value,
password: isCheck.value ? password.value : '',
@ -96,12 +95,13 @@ function handleCommentSubmit() {
});
}
watch(() => props.passwordAlert, () => {
watch(
() => props.passwordAlert,
() => {
if (!props.passwordAlert) {
comment.value = '';
password.value = '';
}
});
},
);
</script>