Custom Template - Hide / Show Column

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
shahparzsoft
User
Posts: 361

Custom Template - Hide / Show Column

Post by shahparzsoft »

I want to show / hide a column in Custom Template based on another column.

For example, if <column1> = 'No' then open another column
if <column1> = 'Yes' then no action.

It is on Add page. I have a field with Yes/No Radio Button.
When somebody select No, then some hidden columns should be show up,
else they should remain hidden.

Kindly help.


mobhar
User
Posts: 11727

Post by mobhar »

Basically, if you want to show/hide the element on the Add form/page, then you may simply use jQuery code and put it in "Startup Script" section. This rule also should be applied for Custom Templates


shahparzsoft
User
Posts: 361

Post by shahparzsoft »

I was using following script in field sms_category Edit Tag -> Custom Attribute:

"onFocus='show_hid()' onKeyDown='show_hid()' onKeyUp='show_hid()'";

and following in ClientScript ->Global->TableSpecific Add/Copy Page->StartupScript:

$("#r_sms_group1").hide();
$("#r_study_in_batch").hide();
$("#r_timing").hide();
$("#r_campus_id").hide();
$("#r_upload_file").hide();
$("#x_sms_category").change(function() {

if ($(this).val() == "File Upload") {
$("#r_upload_file").show();
$("#r_sms_group1").hide();
$("#r_study_in_batch").hide();
$("#r_timing").hide();
$("#r_campus_id").hide();
}

if ($(this).val() == "Batch Wise" || $(this).val() == "Defaulters Message") {
$("#r_upload_file").hide();
$("#r_sms_group1").show();
$("#r_study_in_batch").show();
$("#r_timing").show();
$("#r_campus_id").show();
}
});

When i applied in Simple form, it is working fine, but when i convert it in Custom Template, it didn't work.

please advise.


mobhar
User
Posts: 11727

Post by mobhar »

You need to add manually the id selector into the related elements in your Custom Templates by yourself.


shahparzsoft
User
Posts: 361

Post by shahparzsoft »

No idea how to do that. Can u help with a sample code please,
i will be thankful.


mobhar
User
Posts: 11727

Post by mobhar »

Let me give you the clue for this. If you do View Page Source the HTML code from the normal/built-in Add form/page that generated by PHPMaker (not via Custom Templates), then you should see each row in that page is actually same with each field, and each is identified by the CSS id selector, for example:

<tr id="r_sms_group1">
...
</tr>

<tr id="r_study_in_batch">
...
</tr>

<tr id="r_timing">
...
</tr>

and so forth ...

So, similar to the code above, you need to do that also into your Custom Templates. In other words, each field (row) in that Add form/page must be identified by that id selector, too.


shahparzsoft
User
Posts: 361

Post by shahparzsoft »

Used all variables found in *add.php but unable to hide / show the fields.


mobhar
User
Posts: 11727

Post by mobhar »

Press [F12] from your browser, and see whether any Javascript error from the "Console".


Post Reply