Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

conditional show question

Questions related to using nuBuilder Forte.
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

conditional show question

Unread post 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
admin
Site Admin
Posts: 2829
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 30 times

Re: conditional show question

Unread post by admin »

Johan,

The answer is yes.

But...

Can you explain what you want to do a bit more?

Steven
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: conditional show question

Unread post 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
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: conditional show question

Unread post 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?
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: conditional show question

Unread post by johan »

Toms
That's correct.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: conditional show question

Unread post 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;
}
You do not have the required permissions to view the files attached to this post.
admin
Site Admin
Posts: 2829
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 30 times

Re: conditional show question

Unread post 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
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: conditional show question

Unread post 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
admin
Site Admin
Posts: 2829
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 30 times

Re: conditional show question

Unread post 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
johan
Posts: 422
Joined: Sun Feb 27, 2011 11:16 am
Location: Belgium
Been thanked: 3 times

Re: conditional show question

Unread post by johan »

Steven

I'll try it, just don't know mutch about javascript.
Post Reply