Created
January 31, 2018 13:07
-
-
Save karmadice/6cbb019995496f73a37d6d6cb884a114 to your computer and use it in GitHub Desktop.
Changes to make in QSM plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function qmnDisplayError( message, field, quiz_form_id ) { | |
| jQuery( '#' + quiz_form_id + ' .qmn_error_message_section' ).addClass( 'qmn_error_message' ); | |
| jQuery( '#' + quiz_form_id + ' .qmn_error_message' ).text( message ); | |
| // Targate Span before Input instead of whole container | |
| field.prev('.mlw_qmn_question').addClass( 'qmn_error' ); | |
| //field.closest( '.quiz_section' ).addClass( 'qmn_error' ); | |
| } | |
| function qmnValidation( element, quiz_form_id ) { | |
| // Remove Error class before validation start | |
| jQuery(".mlw_qmn_question").removeClass('qmn_error'); | |
| var result = true; | |
| var quiz_id = +jQuery( '#' + quiz_form_id ).find( '.qmn_quiz_id' ).val(); | |
| var email_error = qmn_quiz_data[ quiz_id ].error_messages.email; | |
| var number_error = qmn_quiz_data[ quiz_id ].error_messages.number; | |
| var empty_error = qmn_quiz_data[ quiz_id ].error_messages.empty; | |
| var incorrect_error = qmn_quiz_data[ quiz_id ].error_messages.incorrect; | |
| qmnResetError( quiz_form_id ); | |
| jQuery( element ).each(function(){ | |
| if ( jQuery( this ).attr( 'class' )) { | |
| if( jQuery( this ).attr( 'class' ).indexOf( 'mlwEmail' ) > -1 && this.value !== "" ) { | |
| var x = this.value; | |
| var atpos = x.indexOf('@'); | |
| var dotpos = x.lastIndexOf( '.' ); | |
| if ( atpos < 1 || dotpos < atpos + 2 || dotpos + 2>= x.length ) { | |
| qmnDisplayError( email_error, jQuery( this ), quiz_form_id ); | |
| result = false; | |
| } | |
| } | |
| if ( ( qmn_quiz_data[quiz_id].hasOwnProperty('pagination') && qmn_quiz_data[quiz_id].first_page ) || ( window.localStorage.getItem( 'mlw_time_quiz' + quiz_id ) === null || | |
| window.localStorage.getItem( 'mlw_time_quiz'+quiz_id ) > 0.08 ) ) { | |
| if( jQuery( this ).attr( 'class' ).indexOf( 'mlwRequiredNumber' ) > -1 && this.value === "" && +this.value != NaN ) { | |
| qmnDisplayError( number_error, jQuery( this ), quiz_form_id ); | |
| result = false; | |
| } | |
| if( jQuery( this ).attr( 'class' ).indexOf( 'mlwRequiredText' ) > -1 && this.value === "" ) { | |
| qmnDisplayError( empty_error, jQuery( this ), quiz_form_id ); | |
| result = false; | |
| } | |
| if( jQuery( this ).attr( 'class' ).indexOf( 'mlwRequiredCaptcha' ) > -1 && this.value != mlw_code ) { | |
| qmnDisplayError( incorrect_error, jQuery( this ), quiz_form_id ); | |
| result = false; | |
| } | |
| if( jQuery( this ).attr( 'class' ).indexOf( 'mlwRequiredAccept' ) > -1 && ! jQuery( this ).prop( 'checked' ) ) { | |
| qmnDisplayError( empty_error, jQuery( this ), quiz_form_id ); | |
| result = false; | |
| } | |
| if( jQuery( this ).attr( 'class' ).indexOf( 'mlwRequiredRadio' ) > -1 ) { | |
| check_val = jQuery( this ).find( 'input:checked' ).val(); | |
| if ( check_val == "No Answer Provided" ) { | |
| qmnDisplayError( empty_error, jQuery( this ), quiz_form_id ); | |
| result = false; | |
| } | |
| } | |
| if( jQuery( this ).attr( 'class' ).indexOf( 'qsmRequiredSelect' ) > -1 ) { | |
| check_val = jQuery( this ).val(); | |
| if ( check_val == "No Answer Provided" ) { | |
| qmnDisplayError( empty_error, jQuery( this ), quiz_form_id ); | |
| result = false; | |
| } | |
| } | |
| if( jQuery( this ).attr( 'class' ).indexOf( 'mlwRequiredCheck' ) > -1 ) { | |
| if ( ! jQuery( this ).find( 'input:checked' ).length ) { | |
| qmnDisplayError( empty_error, jQuery( this ), quiz_form_id ); | |
| result = false; | |
| } | |
| } | |
| } | |
| } | |
| }); | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment