WordPress.org

Ready to get started?Download WordPress

Forums

Wp-Pro-Quiz
[resolved] Customs fields variables , the required text displays before submitting the form (2 posts)

  1. preetee
    Member
    Posted 9 months ago #

    Dear all,

    Am a newbie in wordpress, I have installed the plugin and customised it to my theme. It worked fine but i have an issue with required field for the registration form.Is it possible to display the error message only on clicking the "start quiz" button of the form only.

    Right now, it display the message "You must specify a text." below the input field before even submitting the form .
    In the wpProQuiz_front.js, it check if the required text if is required and empty , if so , then it create the invalid message for that input field type.

    this.checkForm = function() {
    				var check = true;
    
    				$e.find('.wpProQuiz_forms input, .wpProQuiz_forms textarea, .wpProQuiz_forms .wpProQuiz_formFields, .wpProQuiz_forms select').each(function() {
    					var $this = $(this);
    					var isRequired = $this.data('required') == 1;
    					var type = $this.data('type');
    					var test = true;
    					var value = $.trim($this.val());
    
    					switch (type) {
    					case typeConst.TEXT:
    					case typeConst.TEXTAREA:
    					case typeConst.SELECT:
    						if(isRequired){
    							test = !funcs.isEmpty(value);
    							console.log(test);
    						}
    
    						break;
    					case typeConst.NUMBER:
    						if(isRequired || !funcs.isEmpty(value))
    							test = !funcs.isEmpty(value) && !isNaN(value);
    
    						break;
    					case typeConst.EMAIL:
    						if(isRequired || !funcs.isEmpty(value))
    							test = !funcs.isEmpty(value) && new RegExp(/^[a-z0-9!#$%&'*+\/=?^_<code>{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_</code>{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/)
                                										.test(value);
    
    						break;
    					case typeConst.CHECKBOX:
    						if(isRequired)
    							test = $this.is(':checked');
    
    						break;
    					case typeConst.YES_NO:
    					case typeConst.RADIO:
    						if(isRequired)
    							test = $this.find('input[type="radio"]:checked').val() !== undefined;
    						break;
    					case typeConst.DATE:
    						var num = 0, co = 0;
    
    						$this.find('select').each(function() {
    							num++;
    							co += funcs.isEmpty($(this).val()) ? 0 : 1;
    						});
    
    						if(isRequired || co > 0)
    							test = num == co;
    
    						break;
    					}
    
    					if(test) {
    
    						$this.siblings('.wpProQuiz_invalidate').hide();
    					} else {
    						check = false;
    						$this.siblings('.wpProQuiz_invalidate').show();
    					}
    
    				});

    Thank you for your kind help. Any helpfull response is greatly appreciated as i need to submit this project today :(

    http://wordpress.org/plugins/wp-pro-quiz/

  2. preetee
    Member
    Posted 9 months ago #

    You must deactivate the autostart option O.o simply so that invalid messages dont show up even before clicking on the start quiz button for register user form

Reply

You must log in to post.

About this Plugin

About this Topic