Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix(answer): Update front-end validation rules for answer content

haitao(lj)783aa0eacf9c
diff --git a/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx b/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx
index 050ce0fd..44cfa2cd 100644
--- a/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx
+++ b/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx
@@ -35,18 +35,36 @@ const Index: FC<Props> = ({ visible = false, data, callback }) => {
const [focusType, setFocusType] = useState('');
const [editorFocusState, setEditorFocusState] = useState(false);
+ const checkValidated = (): boolean => {
+ let bol = true;
+ const { content } = formData;
+
+ if (!content.value || Array.from(content.value.trim()).length < 6) {
+ bol = false;
+ formData.content = {
+ value: content.value,
+ isInvalid: true,
+ errorMsg: t('characters'),
+ };
+ } else {
+ formData.content = {
+ value: content.value,
+ isInvalid: false,
+ errorMsg: '',
+ };
+ }
+
+ setFormData({
+ ...formData,
+ });
+ return bol;
+ };
+
const handleSubmit = () => {
if (!guard.tryNormalLogged(true)) {
return;
}
- if (!formData.content.value) {
- setFormData({
- content: {
- value: '',
- isInvalid: true,
- errorMsg: t('empty'),
- },
- });
+ if (!checkValidated()) {
return;
}
postAnswer({
diff --git a/ui/src/pages/Questions/EditAnswer/index.tsx b/ui/src/pages/Questions/EditAnswer/index.tsx
index e4bf5037..10272c65 100644
--- a/ui/src/pages/Questions/EditAnswer/index.tsx
+++ b/ui/src/pages/Questions/EditAnswer/index.tsx
@@ -77,12 +77,12 @@ const Index = () => {
let bol = true;
const { content } = formData;
- if (!content.value) {
+ if (!content.value || Array.from(content.value.trim()).length < 6) {
bol = false;
formData.content = {
- value: '',
+ value: content.value,
isInvalid: true,
- errorMsg: '标题不能为空',
+ errorMsg: t('form.fields.answer.feedback.characters'),
};
} else {
formData.content = {