diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index fbde0c140..b917b0710 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -31,9 +31,10 @@ const VaultPage = (props) => { const countRef = useRef(null); const v3Ref = useRef(null); const legacyRef = useRef(null); + const searchButtonRef = useRef(null); useEffect(() => { - validateInput(); + validateForm(); if (title) { loadPage(page, false, true); } @@ -63,7 +64,7 @@ const VaultPage = (props) => { const performSearch = async ({ title, count, v3, legacy }) => { updateUrl(title, page, count, v3, legacy); - if (title !== '') { + if (title && (v3 || legacy)) { try { const response = await request.get( `/api/vault?title=${title}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}` @@ -115,8 +116,8 @@ const VaultPage = (props) => { const title = titleRef.current.value || ''; const count = countRef.current.value || 10; - const v3 = v3Ref.current.checked; - const legacy = legacyRef.current.checked; + const v3 = v3Ref.current.checked != false; + const legacy = legacyRef.current.checked != false; if (update) { setTitle(title); @@ -150,20 +151,22 @@ const VaultPage = (props) => { ); - const validateInput = () => { + const validateForm = () => { + const submitButton = searchButtonRef.current; const textInput = titleRef.current; - const submitButton = document.getElementById('searchButton'); - if (textInput.validity.valid && textInput.value) { - submitButton.disabled = false; - } else { - submitButton.disabled = true; - } + const legacyCheckbox = legacyRef.current; + const v3Checkbox = v3Ref.current; + + const isTextValid = textInput.validity.valid && textInput.value; + const isCheckboxChecked = legacyCheckbox.checked || v3Checkbox.checked; + + submitButton.disabled = !(isTextValid && isCheckboxChecked); }; const renderForm = () => (