File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -76,11 +76,9 @@ form.addEventListener('submit', (event) => {
76
76
if ( validation ( ) ) {
77
77
buttonSubmitForm . classList . add ( 'form__submit_sending' ) ;
78
78
buttonSubmitForm . textContent = 'Sending...' ;
79
- const formName = document . getElementById ( 'name' ) . value ;
80
- const formEmail = document . getElementById ( 'email' ) . value ;
81
- const formText = document . getElementById ( 'textarea' ) . value ;
79
+ const { formName, formEmail, formText} = event . currentTarget . elements ;
82
80
console . log ( formName , formEmail , formText ) ;
83
- let response = fetch ( 'http ://localhost:3000 ' , {
81
+ fetch ( 'https ://jsonplaceholder.typicode.com/posts ' , {
84
82
method : 'POST' ,
85
83
mode :'no-cors' ,
86
84
headers : {
@@ -91,14 +89,17 @@ form.addEventListener('submit', (event) => {
91
89
email : formEmail ,
92
90
text : formText
93
91
} )
94
- } ) ;
95
- if ( response . ok ) {
92
+ } )
93
+ . then ( function ( ) {
96
94
buttonSubmitForm . classList . add ( 'form__submit_success' ) ;
97
95
buttonSubmitForm . textContent = 'Sent!' ;
98
- } else {
99
- alert ( 'Oops... Something went wrong :(' ) ;
100
- closeForm ( ) ;
101
- }
96
+ form . reset ( ) ;
97
+ setTimeout ( function ( ) {
98
+ buttonSubmitForm . classList . remove ( 'form__submit_success' ) ;
99
+ buttonSubmitForm . classList . remove ( 'form__submit_sending' ) ;
100
+ buttonSubmitForm . textContent = 'Send' ;
101
+ } , 2000 ) ;
102
+ } ) ;
102
103
}
103
104
} ) ;
104
105
You can’t perform that action at this time.
0 commit comments