Is it possible to nest functions for show and hide fields? I

Posted by Paulh0763 on 24-Feb-2016 13:02

Need to know how to nest functions to show/hide fields on a 3 column section.  Snippet of code provided for one field working. Also, when I create more than one Script Component the fields shift (go from Column 2 to 3) and one field does not appear at all.

<script>
document.getElementById("activity_type").onchange = mtgSet;
function mtgSet(){
var mtgSet = rbf_getFieldValue("activity_type")
if(mtgSet == '73105852' || mtgSet == '73105859'){

hideField();
$('#rbi_F_meeting_set_').show();
$('#rbi_L_meeting_set_').show();

}
else if(mtgSet != '73105852' || mtgSet != '73105859'){

hideField();
$('#rbi_F_meeting_set_').hide();
$('#rbi_L_meeting_set_').hide();
}
}
function hideField()
{
$('#rbi_F_meeting_set_').show();
$('#rbi_L_meeting_set_').show();
}
</script>

Or...is it better to enable and disable fields? If so, how would I do that?

As always - any help is appreciated. Hopefully, I have explained enough???

Thanks, Paul

All Replies

Posted by jsniemi79 on 24-Feb-2016 13:55

Paul, this is certainly possible.  What are the three fields that you want to hide/show.  Also, what is the business logic that determines whether they are displayed or not?  If you send that, I'll try and write you a little code to make it work.

Jason

Posted by Paulh0763 on 24-Feb-2016 14:03

The fields are Other (text field), Revenue Proposed (currency), and Meeting Set (group of checkboxes).

If Activity Type (lookup field...set as a picklist)  equals Initial Presentation, show Revenue Proposed field...otherwise hide the field.  If Activity Type is either Initial Intro Call or Initial Intro Email show Meeting Set field, otherwise hide it. If Result field (picklist - with codes) equals Other show Other-Specified field, otherwise hide it.

Thanks for the help.

Posted by Thierry Ciot on 24-Feb-2016 21:54
Paul,
 
In regard to “the fields shift (go from Column 2 to 3)”, this is expected as you are hiding a complete column from the responsive row.  In V4.0.5, we have introduced a new parameter to let you decide if, for example when hiding field in column 2, the field in column 3 remains where it is or takes field in column 2 position.
 
 
As the screenshots illustrate how it behaves in relation to a smaller screen size.
 
Thierry.
 
Posted by Paulh0763 on 25-Feb-2016 06:50

Hello Thierry,

I appreciate the additional information but we are currently on a rather old version 2.2.2.0 to be exact so the information you provided is of no use at this time to me. I know we are slated to upgrade to 4.0 a more recent version but we are testing in our QA environment before we roll it out. Jason mentioned he may be able to provide some detail for me to do this as well, so I will see what he comes up with.

Thanks again,

Paul

Posted by jsniemi79 on 25-Feb-2016 07:58

Paul,

Here is some code that should work for you. You'll need to update the field names in each section and the IDs of the values on the activity type picklist before it will work.  In addition, if you need this to default when the page is loaded in addition to the onchange event, you can add mtgSet(); to the onload section on the page property.  That will run the trigger on load and the fields will hide/show depending on the default value of the activity type checkbox.  As for the column issue, Thierry is correct, that is default behavior.  I hope this works.  Let me know if you have any questions.

<script>
document.getElementById("activity_type").onchange = mtgSet;
function mtgSet()
{
//Get the current activity type value
var activityType = rbf_getFieldValue("activity_type");

//set the field name and default value of false for the meeting set
var meeting = "meeting_set_";
var mtgSet = false;

//Check the value of the current activity type and set mtgSet to true if it matches the two values
if (activityType == '73105852' || acitivityType == '73105859')
{
mtgSet = true;
}

//Call the setVisiblity function for the meeting set field
setVisibility(meeting, mtgSet);

//set the field name and default value of false for the Other special Field
var otherField = "Add field name here";
var otherSet = false;

// Set the visibility to true if activity set to Other
if (activityType == 'Other')
{
otherSet = true;
}

//Call the setVisiblity function for the meeting set field
setVisibility(otherField, otherSet);

//Set the field name and default value of false for the revenue field
var revField = "Add field name here";
var revSet = false;

//Check if activity type is presentation and set the value to true for the rev field
if (activityType == 'Presentation')
{
revSet = true;
}

//Call the setVisiblity function for the meeting set field
setVisibility(revField, revSet);
}

//function to accept the fieldname and value that will hide both the label and input using the Rollbase showOrHideField api
function setVisibility(fieldName, showField)
{
rbf_showOrHideField(fieldName, showField);
}
</script>

This thread is closed