Search code examples
gigya

JavaScript Custom event is occuring in a loop after pressing submit button


For JS custom event after clicking the submit button on the second progressive profiling screenevent==='afterSubmit', this whole event keeps repeating again and again until I close it. I am using e.stopImmediatePropagation(); to stop this event but it's not working any tips?


Solution

  • One thing I see is that since you are using the afterSubmit event, and calling accounts.showScreenSet inside it, everytime you press submit on the new screen, it will in turn, call the event again. This is probably not wanted behavior.

    Secondly, it is better to fire the screen only if the field you are checking is empty, not full. The way it is now means that the screen will always fire if the user has already filled out the field.

    You can try this:

    if (e.eventName === 'afterSubmit') {
    
                    alert('afterSubmit Fired');
    
                    if (typeof (e.profile.zip) !== 'undefined') {
                        if ((e.profile.zip == '') || (e.profile.zip == null)) {
                            alert('Yo 2nd step..');
                            alert('Zip is empty, please fill out your zipcode on the next screen');
    
                            gigya.accounts.showScreenSet({
                                screenSet: 'New-RegistrationLogin',
                                startScreen: 'Bio'
                            });
                        }
                    }
                }
    

    Also, when adding additional information to an existing user's profile, it is recommended best practice to use a screen within the ProfileUpdate screen-set, not the RegistrationLogin screen-set.