@@ -22,6 +22,7 @@ define([
2222 /** @inheritdoc */
2323 _create : function ( ) {
2424 this . _bind ( ) ;
25+ this . bindFormSubmit ( false ) ;
2526 } ,
2627
2728 /**
@@ -63,12 +64,6 @@ define([
6364 isFileUploaded = false ,
6465 self = this ;
6566
66- if ( event . handleObj . selector == this . options . qtyInfo ) { //eslint-disable-line eqeqeq
67- this . _updateAddToWishlistButton ( { } ) ;
68- event . stopPropagation ( ) ;
69-
70- return ;
71- }
7267 $ ( event . handleObj . selector ) . each ( function ( index , element ) {
7368 if ( $ ( element ) . is ( 'input[type=text]' ) ||
7469 $ ( element ) . is ( 'input[type=email]' ) ||
@@ -89,9 +84,7 @@ define([
8984 }
9085 } ) ;
9186
92- if ( isFileUploaded ) {
93- this . bindFormSubmit ( ) ;
94- }
87+ this . bindFormSubmit ( isFileUploaded ) ;
9588 this . _updateAddToWishlistButton ( dataToAdd ) ;
9689 event . stopPropagation ( ) ;
9790 } ,
@@ -190,33 +183,41 @@ define([
190183 /**
191184 * Bind form submit.
192185 */
193- bindFormSubmit : function ( ) {
186+ bindFormSubmit : function ( isFileUploaded ) {
194187 var self = this ;
195188
196- $ ( '[data-action="add-to-wishlist"]' ) . on ( 'click' , function ( event ) {
189+ $ ( '[data-action="add-to-wishlist"]' ) . off ( 'click' ) . on ( 'click' , function ( event ) {
197190 var element , params , form , action ;
198191
199- event . stopPropagation ( ) ;
200- event . preventDefault ( ) ;
192+ if ( ! $ ( $ ( self . options . qtyInfo ) . closest ( 'form' ) ) . valid ( ) ) {
193+ event . stopPropagation ( ) ;
194+ event . preventDefault ( ) ;
201195
202- element = $ ( 'input[type=file]' + self . options . customOptionsInfo ) ;
203- params = $ ( event . currentTarget ) . data ( 'post' ) ;
204- form = $ ( element ) . closest ( 'form' ) ;
205- action = params . action ;
206-
207- if ( params . data . id ) {
208- $ ( '<input>' , {
209- type : 'hidden' ,
210- name : 'id' ,
211- value : params . data . id
212- } ) . appendTo ( form ) ;
196+ return ;
213197 }
214198
215- if ( params . data . uenc ) {
216- action += 'uenc/' + params . data . uenc ;
199+ if ( isFileUploaded ) {
200+ element = $ ( 'input[type=file]' + self . options . customOptionsInfo ) ;
201+ params = $ ( event . currentTarget ) . data ( 'post' ) ;
202+ form = $ ( element ) . closest ( 'form' ) ;
203+ action = params . action ;
204+
205+ if ( params . data . id ) {
206+ $ ( '<input>' , {
207+ type : 'hidden' ,
208+ name : 'id' ,
209+ value : params . data . id
210+ } ) . appendTo ( form ) ;
211+ }
212+
213+ if ( params . data . uenc ) {
214+ action += 'uenc/' + params . data . uenc ;
215+ }
216+
217+ $ ( form ) . attr ( 'action' , action ) . submit ( ) ;
218+ event . stopPropagation ( ) ;
219+ event . preventDefault ( ) ;
217220 }
218-
219- $ ( form ) . attr ( 'action' , action ) . submit ( ) ;
220221 } ) ;
221222 }
222223 } ) ;
0 commit comments