- Regular Section
- Validate sum of numeric question against manually entered total
- Validate two responses match
- Validate whether one answer exceeds another number
- Validate whether one answer is between a number and a manually entered response
- Validate whether one answer is greater than a manually entered response
- Validate the barcode scanned and manually entered code match
- Validate a date response is today or before today.
- Validate two date responses match
- Validate end time response is after start time response
- Validate an option cannot be selected if one option is checked in a multipicklist question
- Validate picklist values are particular options
- Validate that the answer to the single select was one of the selections in the previous multi-select question
- Validate if the value selected contains “None” and if more than one options are selected
- Repeat Section
- Validate that there is a response to 1 of 2 questions
- Validate two responses match
- Validate whether one answer is between a number and a manually entered response
- Validate whether one answer is greater than a manually entered response
- Validate that there is a response
- Validate that the answer to the single select was one of the selections in the previous multi-select question.
- Validate if the value selected contains “None” and if more than one options are selected.
- Regular Section
-
Validate sum of numeric question against manually entered total
-
-
Regular Section: client_id
Question 1 Caption: How much land do you use for crop 1?
Question 1 Name: how_much_land_do_you_use_for_crop_1
Question 2 Caption: How much land do you use for crop 2?
Question 2 Name: how_much_land_do_you_use_for_crop_2
Question 3 Caption: How much land do you use for crop 3?
Question 3 Name: how_much_land_do_you_use_for_crop_3
Question 4 Caption: How much total land do you have?
Question 4 Name: how_much_total_land_do_you_have/*JavaScript code on Q4*/
var totalLandForCrops = tw.client_id.how_much_land_do_you_use_for_crop_1.value + tw.client_id.how_much_land_do_you_use_for_crop_2.value +
tw.client_id.how_much_land_do_you_use_for_crop_3.value;
if (tw.client_id.how_much_total_land_do_you_have.value < totalLandForCrops)
{
throw "Total land owned cannot be less than total land used for crops";
}
-
-
- Validate two responses match
Compare Q1 vs Q2 and if it's not the same throw error-
-
Regular Section: client_id
Q1 Caption: Input your email address
Q1 Name: input_your_email_address
Q2 Caption: Confirm your email address
Q2 Name: confirm_your_email_address/*JavaScript code on Q2*/
if (tw.client_id.input_your_email_address.value !== tw.client_id.confirm_your_email_address.value)
{
throw "Email addresses are not the same.";
}
-
-
- Validate whether one answer exceeds another number
How many secondary school age children are in your HH? How many of those children attend school? > Question 2 should not exceed Question 1-
-
Regular Section: client_id
Q1 Caption: How many secondary school age children are in your HH?
Q1 Name: how_many_secondary_school_age_children_are_in_your_hh
Q2 Caption: How many of those children attend school?
Q2 Name: how_many_of_those_children_attend_school/*JavaScript code on Q2*/
if (tw.client_id.how_many_secondary_school_age_children_are_in_your_hh .value < tw.client_id.how_many_of_those_children_attend_school.value)
{
throw "The number of children that attend school cannot be more than number of secondary school age children in the household.";
}
-
-
- Validate whether one answer is between a number and a manually entered response
Logic: Q2 should be between 0 and Q1 response. If not, show a message like: The answer should be between 0 and 10.....(assuming 10 was Q1 answer)-
-
Regular Section- Client ID
Section Name: client_id
Q1 Caption: How many farmers did you help this month?
Q1 Name: how_many_farmers_did_you_help_this_month
Q2 Caption: How many farmers did you help with Credit?
Q2 Name: how_many_farmers_did_you_help_with_credit/*JavaScript code on Q2*/
if (tw.client_id.how_many_farmers_did_you_help_with_credit.value < 0 ||
tw.client_id.how_many_farmers_did_you_help_with_credit.value > tw.client_id.how_many_farmers_did_you_help_this_month.value)
{
throw "The answer should be between 0 and " + tw.client_id.how_many_farmers_did_you_help_this_month.value;
}
-
-
- Validate whether one answer is greater than a manually entered response
Logic: Q2 should be not be greater than Q1. If not, show a message like: The number of boys cannot be more than 5.....(assuming 5 was Q1 answer)-
-
Regular Section- Client ID
Q1 Caption: How many children?
Q1 Name: how_many_children
Q2 Caption: How many boys?
Q2 Name: how_many_boys/*JavaScript code on Q2*/
if (tw.client_id.how_many_boys.value > tw.client_id.how_many_children.value)
{
throw "The number of boys cannot be more than " + tw.client_id.how_many_children.value;
}
-
-
- Barcode Input Validation
- Validate the barcode scanned and manually entered code match. The problem is that they can't both be mapped into the same field
-
Regular Section- Client ID
Question 1 Caption: Scan barcode ID
Question 1 Name: scan_barcode_id
Question 2: Caption: Enter barcode ID
Question 2: Name: enter_barcode_id/*JavaScript code on Q2*/
if (!!tw.client_id.scan_barcode_id.value && !!tw.client_id.enter_barcode_id.value);
{
throw "You must scan or enter a barcode ID";
}
-
- Validate the barcode scanned and manually entered code match. The problem is that they can't both be mapped into the same field
- Date Validation
-
- Validate a date response is today or before today:
If order date is not equal or less than today, don't let the user continue and show some message like: The order date must be today or a date before-
Regular Section- Client ID
Q1 Caption: Log Order date
Q1 Name: log_order_date/*JavaScript code on Q1*/
var today = new Date();
today.setHours(0,0,0,0); /* getting rid of time part so we are comparing only dates */
if (tw.client_id.log_order_date.value.getTime() > today.getTime())
{
throw "The order date must be today or a date before";
}
-
- Validate a date response is today or before today:
- Validate end time response is after start time response
Compare Delivery Date and Order date and if Delivery Date is not greater than Order date, don't let the user continue and show some message like: The Delivery date must be after Order date-
-
Regular Section- client_id
Q2 Caption: Log the Delivery Date
Q2 Name: log_the_delivery_date/*JavaScript code on Q2*/
if (tw.client_id.log_the_delivery_date.value.getTime() <= tw.client_id.log_order_date.value.getTime())
{
throw "The Delivery date must be after Order date";
}
-
-
- Validate end time response is after start time response
Error Message "The form end date should not be before the form start date"
-
-
Regular Section- Client ID
Q1 Caption: Form start date
Q1 Name: form_start_date
Q2: Caption: Form end date
Q2: Name: form_end_date/*JavaScript code on Q2*/
if (tw.client_id.form_start_date.value.getTime() > tw.client_id.form_end_date.value.getTime())
{
throw "The form end date should not be before the form start date.";
}
-
-
- Validate an option cannot be selected if one option is checked in a multipicklist question.
-
Regular Section- Training
Question 1 Caption: What kind of training did you attend last year?
Question 1 Name: type_of_training_attended/*JavaScript code on Q1*/
if (tw.training.type_of_training_attended.value.contains("None") && tw.training.type_of_training_attended.value !== "None" )
{
throw "None cannot be combined with any other selection" ;
}
-
- Validate picklist values are particular options.
-
Regular Section- application
Question 1 Caption: Are you at least 16 years of age?
Question 1 Name: are_you_at_least_16_years_of_age
Question 2 Caption: Are you at least 14 years of age with a worker's permit?
Question 2 Name: are_you_at_least_14_years_of_age_and_hav/*JavaScript code on Q2*/
if(tw.application.are_you_at_least_16_years_of_age.value== "No" && tw.application.are_you_at_least_14_years_of_age_and_hav.value=="No")
{
throw "You must at least 16 years old or have a work permit.";
}
-
- Validate that the answer to the single select was one of the selections in the previous multi-select question.
-
Regular Section- age_calculation
Question 1 Caption: Hobbies
Question 1 Name: hobbies
Question 2 Caption: Favourite Hobbie
Question 2 Name: select_1_hobbie_from_previous_multiselec/*JavaScript code on Q2*/
if (!tw.age_calculation.hobbies.value.contains(tw.age_calculation.select_1_hobbie_from_previous_multiselec.value)) {throw "Wrong Selection";}
-
- Validate if the value selected contains “None” and if more than one options are selected.
-
Regular Section- beneficiary_information
Question 1 Caption: Favorite Color
Question 1 Name: favorite_color
/*JavaScript code*/
if(tw.beneficiary_information.favorite_color.value.contains("None") && tw.beneficiary_information.favorite_color.value.length > 1 ) { throw "None cannot be combined with any other selection" ;}
-
-
-
- Repeat Section
- Validate that there is a response to 1 of 2 questions
- Have a barcode scanned automatically, and also allow manual entry of the same barcode.
-
Repeat Section- sales_products
Q1 Caption: Scan barcode ID
Q1 Name: scan_barcode
Q2: Caption: Enter barcode ID
Q2: Name: enter_barcode/*JavaScript code on Q2*/
if (!!tw.demographic.current.scan_barcode.hasAnswer && !!tw.demographic.current.enter_barcode.hasAnswer)
{
throw "You must scan or enter a barcode ID".
}
-
- Have a barcode scanned automatically, and also allow manual entry of the same barcode.
- Validate two responses match
- Compare Q1 vs Q2 and if it's not the same don't let the user continue and show some message
-
Repeat Section- Demographic
Q1 Caption: Input your email address
Q1 Name: input_your_email_address
Q2 Caption: Confirm your email address
Q2 Name: confirm_your_email_address/*JavaScript code on Q2*/
if (tw.demographic.current.input_your_email_address.value != tw.demographic.current.confirm_your_email_address.value)
{
throw "Email addresses are not the same.";
}
-
- Validate whether one answer is between a number and a manually entered response.
Logic: Q2 should be between 0 and Q1 response. If not, show a message like: The answer should be between 0 and 10.....(assuming 10 was Q1 answer)-
Repeat Section- Demographic
Q1 Caption: How many farmers did you help this month?
Q1 Name: how_many_farmers_did_you_help_this_month
Q2 Caption: How many farmers did you help with Credit?
Q2 Name: how_many_farmers_did_you_help_with_credit/*JavaScript code on Q2*/
if (tw.demographic.current.how_many_farmers_did_you_help_with_credit.value >= 0 &&
tw.demographic.current.how_many_farmers_did_you_help_with_credit.value <= tw.demographic.current.how_many_farmers_did_you_help_this_month.value)
{
throw "The answer should be between 0 and " + tw.demographic.current.how_many_farmers_did_you_help_this_month.value;
}
-
- Validate whether one answer is greater than a manually entered response.
Logic: Q2 should be not be greater than Q1. If not, show a message-
Repeat Section- Demographic
Q1 Caption: How many children?
Q1 Name: how_many_children
Q2 Caption: How many boys?
Q2 Name: how_many_boys/*JavaScript code on Q2*/
if (tw.demographic.current.how_many_boys.value > tw.demographic.current.how_many_children.value)
{
throw "The number of boys cannot be more than " + tw.Demographic.current.how_many_children.value;
}
-
- Compare Q1 vs Q2 and if it's not the same don't let the user continue and show some message
-
Validate that there is a response.
Example a tabular repeat section where if one column has a value I want to throw an error-
Repeat section has a field for: Coupon Discount and Coupon Discount Code
If Coupon Discount is entered but no Coupon Discount Code, I want it to throw an error.if(tw.order_line_items.current.discount.value > 0 && !tw.order_line_items.current.discount_coupon_code.hasAnswer)
{
throw "You must provide a coupon code for this discount.";
}
-
- Validate that there is a response to 1 of 2 questions
-
Validate that the answer to the single select was one of the selections in the previous multi-select question.
-
Repeat Section- new_section
Question 1 Caption: Select Hobbies
Question 1 Name: select_hobbies
Question 2 Caption: Confirm Hobbies
Question 2 Name: confirm_hobbies
/*JavaScript code on Q2*/
if (!tw.new_section.current.select_hobbies.value.contains(tw.new_section.current.confirm_hobbies.value)) {throw "Wrong Selection";}
-
-
Validate if the value selected contains “None” and if more than one options are selected.
-
Regular Section- beneficiary_information
Question 1 Caption: Favorite Color
Question 1 Name: favorite_color
/*JavaScript code*/
if(tw.beneficiary_information.current.favorite_color.value.contains("None") && tw.beneficiary_information.current.favorite_color.value.length > 1 ) { throw "None cannot be combined with any other selection" ;}
Comments
0 comments
Please sign in to leave a comment.