File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,12 +3,16 @@ defineProps({
33 type: {
44 type: String ,
55 default: ' submit'
6+ },
7+ disabled: {
8+ type: Boolean ,
9+ default: false
610 }
711})
812 </script >
913
1014<template >
11- <button :type =" type" >
15+ <button :type =" type" :disabled = " disabled " >
1216 <slot />
1317 </button >
1418</template >
3337 ' @dark' : {
3438 backgroundColor: ' {color.gray.100}' ,
3539 color: ' {color.gray.900}' ,
40+ },
41+ ' &:disabled' : {
42+ cursor: ' not-allowed' ,
3643 }
3744 }
3845})
Original file line number Diff line number Diff line change @@ -5,10 +5,14 @@ const alpine = useAppConfig().alpine
55
66const { FORMSPREE_URL } = useRuntimeConfig ().public
77
8+ if (! FORMSPREE_URL ) {
9+ console .warn (' No FORMSPREE_URL provided' )
10+ }
11+
812const status = ref ()
913
1014const props = defineProps ({
11- sendButton : {
15+ submitButtonText : {
1216 type: String ,
1317 default: ' Send message'
1418 },
@@ -56,6 +60,8 @@ const onSend = async (e: any) => {
5660 e .preventDefault ()
5761 const data = new FormData (e .target )
5862
63+ status .value = ' Sending...'
64+
5965 fetch (e .target .action , {
6066 method: e .target .method ,
6167 body: data ,
@@ -70,7 +76,11 @@ const onSend = async (e: any) => {
7076 // Handle errors from API
7177 response .json ().then (data => {
7278 if (Object .hasOwn (data , ' errors' )) {
79+ status .value = data [" errors" ][0 ].message
7380 console .error (data [" errors" ].map ((error : any ) => error [" message" ]).join (" , " ))
81+ setTimeout (() => {
82+ status .value = ' Send message'
83+ }, 2000 )
7484 } else {
7585 console .error (" There was a problem submitting your form" )
7686 }
@@ -90,8 +100,8 @@ const onSend = async (e: any) => {
90100 <Input v-for =" (field , index ) in form " :key =" index " v-model =" field .data " :field =" field " />
91101 </div >
92102 <div >
93- <Button type="submit">
94- {{ status ? status : sendButton }}
103+ <Button type="submit" : disabled = " ! FORMSPREE_URL " >
104+ {{ status ? status : submitButtonText }}
95105 </Button >
96106 </div >
97107 </form >
Original file line number Diff line number Diff line change 5757 fontSize: ' {text.base.fontSize}' ,
5858 lineHeight: ' {text.base.lineHeight}' ,
5959 fontWeight: ' {fontWeight.semibold}' ,
60- marginBottom: ' {space.2}'
60+ marginBottom: ' {space.2}' ,
61+ cursor: ' pointer' ,
6162 },
6263 ' input, textarea' : {
6364 backgroundColor: ' transparent' ,
You can’t perform that action at this time.
0 commit comments