@@ -1010,7 +1010,7 @@ async function getData(form) {
10101010 return dataArray ;
10111011}
10121012
1013- async function save ( element ) {
1013+ async function save ( element , action ) {
10141014 if ( ! element ) return ;
10151015 let data , value ;
10161016 let upsert = element . getAttribute ( "upsert" ) ;
@@ -1116,19 +1116,28 @@ async function save(element) {
11161116 ( data [ i ] . type !== "object" &&
11171117 data [ i ] . method . endsWith ( ".update" ) ) )
11181118 ) {
1119- setTypeValue ( element , data [ i ] ) ;
1120- } else if ( data [ i ] )
1121- document . dispatchEvent (
1122- new CustomEvent ( "saved" , {
1123- detail : data [ i ]
1124- } )
1125- ) ;
1119+ setTypeValue ( element , data [ i ] , action ) ;
1120+ } else if ( data [ i ] ) {
1121+ if ( action ) {
1122+ action . element . dispatchEvent (
1123+ new CustomEvent ( "saved" , {
1124+ detail : data
1125+ } )
1126+ ) ;
1127+ } else {
1128+ document . dispatchEvent (
1129+ new CustomEvent ( "saved" , {
1130+ detail : data
1131+ } )
1132+ ) ;
1133+ }
1134+ }
11261135 }
11271136
11281137 return Data ;
11291138}
11301139
1131- function setTypeValue ( element , data ) {
1140+ function setTypeValue ( element , data , action ) {
11321141 // TODO: if an array name is updated, the attibute array="" needs to be updated.
11331142
11341143 if ( ! data ) return ;
@@ -1164,7 +1173,7 @@ function setTypeValue(element, data) {
11641173 }
11651174 setData ( Array . from ( elements . keys ( ) ) , data ) ;
11661175
1167- // const state_ids = new Map();
1176+ // const state_ids = new Map()
11681177
11691178 // let state_id = form.getAttribute('state_id');
11701179 // if (state_id) {
@@ -1217,11 +1226,19 @@ function setTypeValue(element, data) {
12171226 // }
12181227 }
12191228
1220- document . dispatchEvent (
1221- new CustomEvent ( "saved" , {
1222- detail : data
1223- } )
1224- ) ;
1229+ if ( action ) {
1230+ action . element . dispatchEvent (
1231+ new CustomEvent ( "saved" , {
1232+ detail : data
1233+ } )
1234+ ) ;
1235+ } else {
1236+ document . dispatchEvent (
1237+ new CustomEvent ( "saved" , {
1238+ detail : data
1239+ } )
1240+ ) ;
1241+ }
12251242}
12261243
12271244async function remove ( element ) {
@@ -1503,7 +1520,7 @@ Actions.init([
15031520 name : "save" ,
15041521 endEvent : "saved" ,
15051522 callback : ( action ) => {
1506- if ( action . form ) save ( action . form ) ;
1523+ if ( ( action . form , action ) ) save ( action . form , action ) ;
15071524 }
15081525 } ,
15091526 {
@@ -1546,7 +1563,7 @@ Actions.init([
15461563 data [ data . type ] = { _id : data [ data . type ] } ;
15471564
15481565 let response = await CRUD . send ( data ) ;
1549- document . dispatchEvent (
1566+ action . element . dispatchEvent (
15501567 new CustomEvent ( "deleted" , {
15511568 detail : response
15521569 } )
0 commit comments