Просмотр исходного кода

Change to form tag and include check for manual button press

arvid-e 2 недель назад
Родитель
Сommit
ee7796905b

+ 17 - 4
apps/app/src/client/components/Admin/MarkdownSetting/ContentDispositionSettings.tsx

@@ -1,5 +1,5 @@
 import type React from 'react';
 import type React from 'react';
-import { useCallback, useEffect, useState } from 'react';
+import { useCallback, useEffect, useRef, useState } from 'react';
 import { useTranslation } from 'next-i18next';
 import { useTranslation } from 'next-i18next';
 import { useForm } from 'react-hook-form';
 import { useForm } from 'react-hook-form';
 
 
@@ -70,6 +70,7 @@ const ContentDispositionSettings: React.FC = () => {
 
 
   const [currentInput, setCurrentInput] = useState<string>('');
   const [currentInput, setCurrentInput] = useState<string>('');
   const [error, setError] = useState<string | null>(null);
   const [error, setError] = useState<string | null>(null);
+  const isManualSubmit = useRef(false);
 
 
   const {
   const {
     handleSubmit,
     handleSubmit,
@@ -138,6 +139,10 @@ const ContentDispositionSettings: React.FC = () => {
   );
   );
 
 
   const onSubmit = async (data: ContentDispositionSettingsType) => {
   const onSubmit = async (data: ContentDispositionSettingsType) => {
+    if (!isManualSubmit.current) {
+      return;
+    }
+
     try {
     try {
       setError(null);
       setError(null);
       await updateSettings(data);
       await updateSettings(data);
@@ -159,7 +164,7 @@ const ContentDispositionSettings: React.FC = () => {
   if (isLoading && !currentSettings) return <div>Loading...</div>;
   if (isLoading && !currentSettings) return <div>Loading...</div>;
 
 
   return (
   return (
-    <div className="row">
+    <form className="row" onSubmit={handleSubmit(onSubmit)}>
       <div className="col-12">
       <div className="col-12">
         <h2 className="mb-4 border-0">
         <h2 className="mb-4 border-0">
           {t('markdown_settings.content-disposition_header')}
           {t('markdown_settings.content-disposition_header')}
@@ -178,6 +183,11 @@ const ContentDispositionSettings: React.FC = () => {
                   value={currentInput}
                   value={currentInput}
                   onChange={(e) => setCurrentInput(e.target.value)}
                   onChange={(e) => setCurrentInput(e.target.value)}
                   placeholder="e.g. image/png"
                   placeholder="e.g. image/png"
+                  onKeyDown={(e) => {
+                    if (e.key === 'Enter') {
+                      e.preventDefault();
+                    }
+                  }}
                 />
                 />
                 <button
                 <button
                   className="btn btn-primary px-3 flex-shrink-0 rounded-3 fw-bold"
                   className="btn btn-primary px-3 flex-shrink-0 rounded-3 fw-bold"
@@ -241,11 +251,14 @@ const ContentDispositionSettings: React.FC = () => {
         </div>
         </div>
 
 
         <AdminUpdateButtonRow
         <AdminUpdateButtonRow
-          onClick={handleSubmit(onSubmit)}
+          onClick={() => {
+            isManualSubmit.current = true;
+            handleSubmit(onSubmit)();
+          }}
           disabled={!isDirty || isUpdating}
           disabled={!isDirty || isUpdating}
         />
         />
       </div>
       </div>
-    </div>
+    </form>
   );
   );
 };
 };