@@ -193,7 +193,10 @@ const inject = {
193
193
const $button = $ ( e . target ) ;
194
194
const formaction = $button . attr ( "formaction" ) ;
195
195
const $form = $button . parents ( ".pat-inject" ) . first ( ) ;
196
- const opts = { url : formaction } ;
196
+ const opts = {
197
+ url : formaction ,
198
+ $formaction_button : $button ,
199
+ } ;
197
200
const $cfg_node = $button . closest ( "[data-pat-inject]" ) ;
198
201
const cfgs = this . extractConfig ( $cfg_node , opts ) ;
199
202
@@ -239,6 +242,15 @@ const inject = {
239
242
$el . parents ( "form" ) . attr ( "action" ) ||
240
243
"" ;
241
244
245
+ if (
246
+ opts . $formaction_button &&
247
+ ( cfg . target || "" ) . startsWith ( "self" )
248
+ ) {
249
+ // In case of button formaction submit with target ``self``,
250
+ // set it. Otherwise the ``form`` will be used as target.
251
+ cfg . $target = opts . $formaction_button ;
252
+ }
253
+
242
254
// separate selector from url
243
255
const urlparts = cfg . url . split ( "#" ) ;
244
256
cfg . url = urlparts [ 0 ] ;
@@ -311,9 +323,10 @@ const inject = {
311
323
* cfg.$target.
312
324
*/
313
325
// make sure target exist
314
- if ( cfg . target === "none" )
326
+ if ( cfg . target === "none" ) {
315
327
// special case, we don't want to inject anything
316
328
return true ;
329
+ }
317
330
cfg . $target =
318
331
cfg . $target || ( cfg . target === "self" ? $el : $ ( cfg . target ) ) ;
319
332
if ( cfg . $target . length === 0 ) {
0 commit comments