How to make fields appear dynamically in my view page

Posted by gonzales.pgon@gmail.com on 11-May-2014 05:15

Hi

I have a checkbox and i want certain fields to appear in my view page depending on the value of the checkbox.
I tried messing around with scripts executed on the onload function and i have already detected if my checkbox os checked or not. I need to find a way to hide the fields. I hope you guys could help me 


Posted by Santosh Patel on 11-May-2014 06:28

There is a common solution if all the fields you need to hide or show are encompassed by a section. Meaning you would show or hide entire sections based on your checkbox value. This can be achieved using 2 inbuilt functions as follows (add the script to a script tag in page body or as an onload action - your choice) :

<script>
var updateSections = function() {
var id = rbf_getSectionIdByTitle('Conditional Section Title');
rbf_showOrHideSection(id, $('#mycheckboxselector').prop('checked'));
}

$('#mycheckboxselector').change(updateSections);
</script>

However, if you need to hide or show individual fields which may or may not be in the same section, following jquery snippets could help you.

Depending on the layout of your page, the field maybe  in a table row of it's own or be a cell in a row along with other fields.

- If the field is in a row of it's own (where 'name' is the integration name of the field)

 $('#rbi_F_name').parent().hide();

- If the field is in a row with other fields (multi-column layout)

$('#rbi_F_name').hide();
$('#rbi_L_name').hide();

Note: With individual fields you need to ensure show/hiding both the field and it's label. Rollbase field label has id as rbi_L_<integration_name_of_field> while actual field has id as rbi_F_<integration_name_of_field>

All Replies

Posted by Santosh Patel on 11-May-2014 06:28

There is a common solution if all the fields you need to hide or show are encompassed by a section. Meaning you would show or hide entire sections based on your checkbox value. This can be achieved using 2 inbuilt functions as follows (add the script to a script tag in page body or as an onload action - your choice) :

<script>
var updateSections = function() {
var id = rbf_getSectionIdByTitle('Conditional Section Title');
rbf_showOrHideSection(id, $('#mycheckboxselector').prop('checked'));
}

$('#mycheckboxselector').change(updateSections);
</script>

However, if you need to hide or show individual fields which may or may not be in the same section, following jquery snippets could help you.

Depending on the layout of your page, the field maybe  in a table row of it's own or be a cell in a row along with other fields.

- If the field is in a row of it's own (where 'name' is the integration name of the field)

 $('#rbi_F_name').parent().hide();

- If the field is in a row with other fields (multi-column layout)

$('#rbi_F_name').hide();
$('#rbi_L_name').hide();

Note: With individual fields you need to ensure show/hiding both the field and it's label. Rollbase field label has id as rbi_L_<integration_name_of_field> while actual field has id as rbi_F_<integration_name_of_field>

Posted by gonzales.pgon@gmail.com on 11-May-2014 20:47

Hi Santosh !

It worked!. I am able to hide or show dynamically in my view page. Thank you for all the help :)

This thread is closed