Difference between revisions of "Validate email specified as an open text of a single question"

From Catglobe Wiki
Jump to: navigation, search
m (Solution)
 
(5 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
As a CGS writer <br/>
 
As a CGS writer <br/>
 
I want to validate an email specified as an open text of a single question<br/>
 
I want to validate an email specified as an open text of a single question<br/>
Example<br/>
+
<br/>
 +
<b>Example</b><br/>
 +
<br/>
 
[[Image:Validate_email_-_semi_open_question.png]]
 
[[Image:Validate_email_-_semi_open_question.png]]
 +
 
==Solution==
 
==Solution==
 +
*Add the script below to the question's Javascript property
 +
*Locate the input text box and use <i>validateEmail</i> function to validate the email
 +
==Script==
 
<source lang=javascript>
 
<source lang=javascript>
var qLabel = "Q1";//question's label
+
var qLabel = "Question1";//question's label
 
var openAnswerValue = 1;//the value of answer option which has open text
 
var openAnswerValue = 1;//the value of answer option which has open text
 
var ErrorMessage_InvalidEmail = "Invalid email.";//error message in your needed language
 
var ErrorMessage_InvalidEmail = "Invalid email.";//error message in your needed language
 
    
 
    
var oldQuestionCheck = this.questioncheck;
+
var normalQuestionCheck = questioncheck;
questioncheck = function()
+
function extendedQuestionCheck()
 
{
 
{
  if (!oldQuestionCheck())
+
    var valid = normalQuestionCheck();
  return false;
+
    var email = $("input[name='QUESTION." + qLabel + ".Open." + openAnswerValue +"']").val();
 
+
    $(document).ready(function(){
  var email = $("input[name='QUESTION." + qLabel + ".Open." + openAnswerValue +"']").val();
+
        $("input:radio[name='QUESTION." + qLabel+"']").each(function(index) {
 
+
 
  if (!validateEmail(email))
+
          if($(this).val() == openAnswerValue && email != ""){
  {
+
              valid = validateEmail(email);
      ErrorMessages.getInstance().showErrorMessage(ErrorMessage_InvalidEmail);
+
          }       
      return false;
+
        });
  }
+
    }); 
 
+
    if (!valid)
  return true;
+
    {
 +
      ErrorMessages.getInstance().showErrorMessage(ErrorMessage_InvalidEmail);
 +
      return false;
 +
    }
 +
    else 
 +
      return true;
 
}
 
}
 +
questioncheck = extendedQuestionCheck;
 
</source>
 
</source>
 +
== Source ==
 +
Questionnaire Resource Id on cg.catglobe.com site: 164079 (Question: Q15_Validate_email_specified_as_an_open_text)

Latest revision as of 09:02, 6 February 2012

Challenge

In order to secure my questionnaire's input
As a CGS writer
I want to validate an email specified as an open text of a single question

Example

Validate email - semi open question.png

Solution

  • Add the script below to the question's Javascript property
  • Locate the input text box and use validateEmail function to validate the email

Script

var qLabel = "Question1";//question's label
var openAnswerValue = 1;//the value of answer option which has open text
var ErrorMessage_InvalidEmail = "Invalid email.";//error message in your needed language
   
var normalQuestionCheck = questioncheck;
function extendedQuestionCheck()
{
    var valid = normalQuestionCheck();
    var email = $("input[name='QUESTION." + qLabel + ".Open." + openAnswerValue +"']").val();
     $(document).ready(function(){ 
        $("input:radio[name='QUESTION." + qLabel+"']").each(function(index) {

           if($(this).val() == openAnswerValue && email != ""){
               valid = validateEmail(email); 
           }        
        });
    });  
    if (!valid)
    {
       ErrorMessages.getInstance().showErrorMessage(ErrorMessage_InvalidEmail);
       return false;
    }
    else  
      return true;
}
questioncheck = extendedQuestionCheck;

Source

Questionnaire Resource Id on cg.catglobe.com site: 164079 (Question: Q15_Validate_email_specified_as_an_open_text)