This topic is locked
[SOLVED]

 Show / Hide Image Field

8/2/2011 7:52:01 AM
PHPRunner General questions
H
hsan author

Is it possible to toggle show/hide Image Field of the particular record by selecting / deselecting the record in the List Page?
Thanks

C
cgphp 8/2/2011

Insert a Button in the visual editor using "Insert Button" from the toolbar.
In the "Client Before" section, enter:

$("input[type='checkbox']:checked").each(function(e){

$(this).parents().eq(1).find("td span[id*='your_image_field_name'] a").toggle();

});



Leave the "Server" and the "Client After" sections as blank page.
This is only a possible solution.

H
hsan author 8/2/2011



Insert a Button in the visual editor using "Insert Button" from the toolbar.
In the "Client Before" section, enter:

$("input[type='checkbox']:checked").each(function(e){

$(this).parents().eq(1).find("td span[id*='your_image_field_name'] a").toggle();

});



Leave the "Server" and the "Client After" sections as blank page.
This is only a possible solution.


Cristian, thanks for your help. I wanted this toggle to happen when i check standard record checkbox in the listview. Anyway, I've created button and added your code, but it did not work.

C
cgphp 8/2/2011

Anyway, this piece of code should work for each selected checkbox when you click on the button.
Have you relpaced "your_image_field_name" with the right name of your image field ? Pay attention to capitalization.

H
hsan author 8/2/2011



Anyway, this piece of code should work for each selected checkbox when you click on the button.
Have you relpaced "your_image_field_name" with the right name of your image field ? Pay attention to capitalization.


Yes I've entered correct field name, yet it does not work. If I select (or deselect) a record and click the button nothing happens. Just to clarify - I am not selecting a field with checkbox, I am selecting entire record.
Thanks

C
cgphp 8/2/2011

I see. After clicking on the button, check if firebug throws some errors.

H
hsan author 8/2/2011



I see. After clicking on the button, check if firebug throws some errors.


No errors by FB.
Thanks

C
cgphp 8/2/2011

The following piece of code doesn't make use of a button. Place it in the Javascript OnLoad event of the list page:

$("input[type='checkbox']").click(function(e){

$(this).parents().eq(1).find("td span[id*='your image_field_name'] a").toggle();

});



Replace "your image_field_name" with the real name of the field.

H
hsan author 8/2/2011



The following piece of code doesn't make use of a button. Place it in the Javascript OnLoad event of the list page:

$("input[type='checkbox']").click(function(e){

$(this).parents().eq(1).find("td span[id*='your image_field_name'] a").toggle();

});



Replace "your image_field_name" with the real name of the field.


Cristian I tried this but it also did not work. It did not produce any change that I can see.
Thanks

C
cgphp 8/2/2011

Please, could you post a link to the demo of your app ?

H
hsan author 8/2/2011



Please, could you post a link to the demo of your app ?


It is on localhost now, but let me post it somewhere I will let you know as soon as it is live.
Thanks

C
cgphp 8/2/2011

You can use the Demo account (http://xlinesoft.com/phprunner/docs/what_is_demoaccount.htm). The link can be sent to me through PM if you don't want to make it public.

C
cgphp 8/3/2011

Your image is not clickable. Try out this solution:

$("input[type='checkbox']").click(function(e){

$(this).parents().eq(1).find("td span[id*='your image_field_name'] img").toggle();

});
H
hsan author 8/3/2011



Your image is not clickable. Try out this solution:

$("input[type='checkbox']").click(function(e){

$(this).parents().eq(1).find("td span[id*='your image_field_name'] img").toggle();

});



Christian,
Thanks a million. That worked! The only thing is that it works opposite - unchecked displays image and checked does not. How can I reverse that?
Thanks

C
cgphp 8/3/2011

Are images hidden by default when the page is loaded ?

H
hsan author 8/3/2011



Are images hidden by default when the page is loaded ?


No when page is loaded images show and check boxes are unchecked. When I check checkbox, then image disappears.

C
cgphp 8/3/2011



Thanks a million. That worked! The only thing is that it works opposite - unchecked displays image and checked does not. How can I reverse that?


You have to hide the images when the page is loaded, so when you'll enable the checkbox the image will be displayed.

H
hsan author 8/3/2011



You have to hide the images when the page is loaded, so when you'll enable the checkbox the image will be displayed.


It would be perfect solution. How do I do that? Do I simply disable that column or I need to use javascrip?
Thanks

C
cgphp 8/3/2011
$("td span[id*='your_image_field_name'] img").hide();
$("input[type='checkbox']").click(function(e){

$(this).parents().eq(1).find("td span[id*='your_image_field_name'] img").toggle();

});
H
hsan author 8/3/2011


$("td span[id*='your_image_field_name'] img").hide();
$("input[type='checkbox']").click(function(e){

$(this).parents().eq(1).find("td span[id*='your_image_field_name'] img").toggle();

});



Thanks again Cristian that works nicely. Sorry for my ignorance, I am still learning.