@@ -30,6 +30,7 @@ export default class DOMPatch {
3030 let focused = liveSocket . getActiveElement ( )
3131 let { selectionStart, selectionEnd} = focused && DOM . hasSelectionRange ( focused ) ? focused : { }
3232 let phxUpdate = liveSocket . binding ( PHX_UPDATE )
33+ let externalFormTriggered = null
3334
3435 morphdom ( container , clonedTree , {
3536 childrenOnly : false ,
@@ -42,9 +43,19 @@ export default class DOMPatch {
4243 DOM . mergeFocusedInput ( fromEl , toEl )
4344 return false
4445 }
46+ if ( DOM . isNowTriggerFormExternal ( toEl , liveSocket . binding ( PHX_TRIGGER_ACTION ) ) ) {
47+ externalFormTriggered = toEl
48+ }
4549 }
4650 } )
4751
52+ if ( externalFormTriggered ) {
53+ liveSocket . unload ( )
54+ // use prototype's submit in case there's a form control with name or id of "submit"
55+ // https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit
56+ Object . getPrototypeOf ( externalFormTriggered ) . submit . call ( externalFormTriggered )
57+ }
58+
4859 liveSocket . silenceEvents ( ( ) => DOM . restoreFocus ( focused , selectionStart , selectionEnd ) )
4960 }
5061
@@ -228,7 +239,7 @@ export default class DOMPatch {
228239 return false
229240 }
230241 if ( fromEl . type === "number" && ( fromEl . validity && fromEl . validity . badInput ) ) { return false }
231- // If the element has PHX_REF_SRC, it is loading or locked and awaiting an ack.
242+ // If the element has PHX_REF_SRC, it is loading or locked and awaiting an ack.
232243 // If it's locked, we clone the fromEl tree and instruct morphdom to use
233244 // the cloned tree as the source of the morph for this branch from here on out.
234245 // We keep a reference to the cloned tree in the element's private data, and
0 commit comments