Page 1 of 2
conditional show question
Posted: Tue Mar 06, 2018 6:14 am
by johan
Hi
I want to show a question on a subform if the answer on a other question = true.
I can't add any JavaScript on a subform
Is it possible?
Johan
Re: conditional show question
Posted: Tue Mar 06, 2018 7:09 am
by admin
Johan,
The answer is yes.
But...
Can you explain what you want to do a bit more?
Steven
Re: conditional show question
Posted: Tue Mar 06, 2018 7:16 am
by johan
Steven
I have 2 questions on my subform. If the answer on q1 is yes I want to show question2. Else hide question2
Johan
Re: conditional show question
Posted: Tue Mar 06, 2018 7:26 am
by toms
Johan,
If I understand you correctly, you want hide the entire (second) row if yes is chosen (in select/dropdown ?) in the first row?
Re: conditional show question
Posted: Tue Mar 06, 2018 7:40 am
by johan
Toms
That's correct.
Re: conditional show question
Posted: Tue Mar 06, 2018 8:55 am
by toms
Try this:
Add an onclick event handler for you yes/no Field:
onchange.PNG
Code: Select all
hideSecondRowIfFirstQuestionYes('replacewithyoursubformname','replacewithyouryesnofield');
Add this code in the main form's JavaScript field:
Code: Select all
function hideSecondRowIfFirstQuestionYes(subform, yesNoField) {
var arr = subGridGetRowArray(subform, yesNoField);
$('#'+subform+'001nuRECORD').css("visibility", (arr[0] == 'yes') ? "visible" : "hidden");
}
// helper function, might be an overkill for your task but useful for other purposes..
function subGridGetRowArray(subform, fieldname) {
var a = Array();
var sf = nuSubformObject(subform);
var c = sf.fields.indexOf(fieldname);
for (var i = 0; i < sf.rows.length; i++) {
if (sf.deleted[i] == 0) {
var rv = sf.rows[i][c];
a.push(rv);
}
}
return a;
}
Re: conditional show question
Posted: Tue Mar 06, 2018 7:58 pm
by admin
Johan,
You could do this...
Code: Select all
function showRow(row){
$("[id^='sf'][id$='nuRECORD']").hide(); //-- hide all rows from subform (sf)
$('#sf' + nuPad3(row) + 'nuRECORD').show(); //-- show "row" of subform (sf)
}
Steven
Re: conditional show question
Posted: Thu Mar 08, 2018 7:21 pm
by johan
Steven, Toms
Is it correct that your solution will hide the next row of a subform?
I just want to hide another question in the same row of my subform.
Johan
Re: conditional show question
Posted: Thu Mar 08, 2018 7:49 pm
by admin
Johan,
Code: Select all
function showRow(row){
$("[id^='sf'][id$='nuRECORD']").hide(); //-- hide all rows from subform (sf)
$('#sf' + nuPad3(row) + 'nuRECORD').show(); //-- show "row" of subform (sf)
}
The code above hides all rows and then displays just one - I suggest you try it and then customise it to exactly what you want.
Steven
Re: conditional show question
Posted: Thu Mar 08, 2018 8:08 pm
by johan
Steven
I'll try it, just don't know mutch about javascript.