@@ -9,8 +9,6 @@ export { client }
99
1010export default function ( Alpine : TAlpine ) {
1111 Alpine . magic ( 'form' , ( el ) => < Data extends Record < string , unknown > > ( method : RequestMethod | ( ( ) => RequestMethod ) , url : string | ( ( ) => string ) , inputs : Data , config : ValidationConfig = { } ) : Data & Form < Data > => {
12- syncWithDom ( el , resolveMethod ( method ) , resolveUrl ( url ) )
13-
1412 /**
1513 * The original data.
1614 */
@@ -162,21 +160,24 @@ export default function (Alpine: TAlpine) {
162160 */
163161 const form = Alpine . reactive ( createForm ( ) ) as Data & Form < Data >
164162
163+ syncWithDom ( el , resolveMethod ( method ) , resolveUrl ( url ) , form )
164+
165165 return form
166166 } )
167167}
168168
169169/**
170170 * Sync the DOM form with the Precognitive form.
171171 */
172- const syncWithDom = ( el : Node , method : RequestMethod , url : string ) : void => {
172+ const syncWithDom = < Data extends Record < string , unknown > > ( el : Node , method : RequestMethod , url : string , form : Form < Data > ) : void => {
173173 if ( ! ( el instanceof Element && el . nodeName === 'FORM' ) ) {
174174 return
175175 }
176176
177177 syncSyntheticMethodInput ( el , method )
178178 syncMethodAttribute ( el , method )
179179 syncActionAttribute ( el , url )
180+ addProcessingListener ( el , form )
180181}
181182
182183/**
@@ -221,3 +222,8 @@ const syncSyntheticMethodInput = (el: Element, method: RequestMethod) => {
221222 input . setAttribute ( 'name' , '_method' )
222223 input . setAttribute ( 'value' , method . toUpperCase ( ) )
223224}
225+
226+ /**
227+ * Add processing listener.
228+ */
229+ const addProcessingListener = < Data extends Record < string , unknown > > ( el : Element , form : Form < Data > ) => el . addEventListener ( 'submit' , ( ) => ( form . processing = true ) )
0 commit comments