File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1313
1414window . wplf = {
1515 successCallbacks : [ ] ,
16- errorCallbacks : [ ]
17- } ;
18-
19- document . addEventListener ( "DOMContentLoaded" , function ( ) {
20- [ ] . forEach . call ( document . querySelectorAll ( ".libre-form" ) , function ( form ) {
16+ errorCallbacks : [ ] ,
17+ attach : function ( form ) {
18+ // form is a selector
19+ if ( typeof form == 'string' )
20+ form = document . querySelectorAll ( form ) ;
21+
22+ // form is an array of elements or a node list
23+ if ( form . constructor === Array || form . constructor === NodeList ) {
24+ [ ] . forEach . call ( form , function ( form ) {
25+ window . wplf . attach ( form ) ;
26+ } ) ;
27+ return ;
28+ }
2129
2230 form . addEventListener ( "submit" , function ( e ) {
2331
@@ -91,6 +99,10 @@ document.addEventListener("DOMContentLoaded", function(){
9199 e . preventDefault ( ) ;
92100 } ) ;
93101
94- } ) ;
102+ }
103+ }
104+
105+ document . addEventListener ( "DOMContentLoaded" , function ( ) {
106+ [ ] . forEach . call ( document . querySelectorAll ( ".libre-form" ) , wplf . attach ) ;
95107} ) ;
96108} ) ( ) ;
You can’t perform that action at this time.
0 commit comments