Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Date pick logic with Weekday or Weekend

I have created free format "Date pick" and grid question in the same page which Row 1 as Weekday/Weekend and Row 2 as Monday to Sunday. I want to create logic check as below:

1. If Respondent select answer in calendar as Saturday or Sunday, they can select answer at Row 1 only "Weekend" and Row 2 only "Saturday" or "Sunday".

2. If Respondent select answer in calendar as Monday to Friday, they can select answer at Row 1 only "Weekday" and Row 2 only "Monday" to "Friday".

Here is your reference :

https://drive.google.com/file/d/1JUDVgwtzeHYQu6OfEPAUi_z9s6ObjBsP/view?usp=sharing

Thanks.
asked Aug 3 by Saroeun Bronze (2,715 points)
edited Aug 3 by Saroeun
Why prompt the respondent for the same info three times?  Why ask the respondent if they are going to choose a weekday or weekend to just ask them for the specific day right after?
Yes, you are right. but my client want like this and they need me to create logic check. Is it possible? please help

1 Answer

+1 vote
 
Best answer
Place this in the grid question's custom verification:

// Params
var calendar = 'Calendar';
var weekend = [1, 7];

// Run
var date = $('#' + calendar + '_datepicker').datepicker('getDate');
var day = date.getDay();
var answeredWeekend1 = day == 0 || day == 6;

var answeredWeekend2 = SSI_GetValue('[% QuestionName() %]_r1_c1') == 2;

var row2Response = SSI_GetValue('[% QuestionName() %]_r2_c1');
var answeredWeekend3 = row2Response == weekend[0] || row2Response == weekend[1];

if (answeredWeekend1 && answeredWeekend2 && !answeredWeekend3) {
    strErrorMessage = 'error 1';
}
else if (answeredWeekend1 && !answeredWeekend2 && answeredWeekend3) {
    strErrorMessage = 'error 2';
}
else if (answeredWeekend1 && !answeredWeekend2 && !answeredWeekend3) {
    strErrorMessage = 'error 3';
}
else if (!answeredWeekend1 && answeredWeekend2 && answeredWeekend3) {
    strErrorMessage = 'error 4';
}
else if (!answeredWeekend1 && answeredWeekend2 && !answeredWeekend3) {
    strErrorMessage = 'error 5';
}
else if (!answeredWeekend1 && !answeredWeekend2 && answeredWeekend3) {
    strErrorMessage = 'error 6';
}


Line 2 should be updated with the name of the calendar question.  Line 3 should be updated with which items in the second dropdown are weekends.

There are six different error states possible; your client can define those errors however they require.
answered Aug 3 by Zachary Platinum Sawtooth Software, Inc. (184,925 points)
selected Aug 3 by Saroeun
...