add form validation
This commit is contained in:
@@ -14,6 +14,9 @@ export default function Nominations() {
|
|||||||
const [songURL, setSongURL] = useState("");
|
const [songURL, setSongURL] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
|
const isSpotifyURL =
|
||||||
|
/^https:\/\/open\.spotify\.com\/track\/[a-zA-Z0-9]{22}/.test(songURL);
|
||||||
|
|
||||||
async function nominate(spotifyLink: string) {
|
async function nominate(spotifyLink: string) {
|
||||||
try {
|
try {
|
||||||
setIsAnimate(false);
|
setIsAnimate(false);
|
||||||
@@ -54,7 +57,7 @@ export default function Nominations() {
|
|||||||
<button
|
<button
|
||||||
className="w-full rounded bg-blue-500 px-4 py-2 text-center font-bold text-white hover:bg-blue-400 disabled:cursor-not-allowed disabled:bg-gray-500"
|
className="w-full rounded bg-blue-500 px-4 py-2 text-center font-bold text-white hover:bg-blue-400 disabled:cursor-not-allowed disabled:bg-gray-500"
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isLoading || !songURL.trim()}
|
disabled={isLoading || !songURL.trim() || !isSpotifyURL}
|
||||||
onClick={async (e) => {
|
onClick={async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!songURL.trim()) return;
|
if (!songURL.trim()) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user