This topic is locked

Show and Hide Edit Selected, Delete Selected buttons

11/16/2010 9:26:27 PM
PHPRunner General questions
D
Dale author

Ver 5.2

Does anyone have a sample or know of a post that deals with this issue, that can help me out.

On my list pages, where I have the functions to Delete Selected, Edit Selected, Print Selected etc etc.

WHen I load the page, with nothing checked these buttons show on the list page.

Any way I can sense if ANY checkbox on a row is checked and then display the above buttons, otherwise Hide them.
Thanks

Sergey Kornilov admin 11/17/2010

jQuery comes to rescue. Add the following code to 'List page: Javascript OnLoad' event.

$('span[@id=record_controls1]').hide();
$('input[@type=checkbox][@name^=selection]').click(function() {

if ($('input[@type=checkbox][@checked][@name^=selection]').length)

{

$('span[@id=record_controls1]').show();

}

else

{

$('span[@id=record_controls1]').hide();

}
});
D
Dale author 11/17/2010

Perfect, works like a charm. I also added the style="display:none" to the id=record_controls{id} span in the list.htm template to hide the controls in the first place.I hate flickering pages. Works like a charm.
But, there is always a but, when I click the Select All checkbox, it does not show and hide the record controls id span.
I tried playing with it but there is already a function attached to the onclick of the chooseAll_1 checkbox.
Any pointers would be appreciated as always.

Sergey Kornilov admin 11/17/2010

Updated code. I highly recommend learning jQuery basics - make wonders with very little code involved.

$('span[@id=record_controls1]').hide();
$('input[@type=checkbox][@name^=selection],[@id^=chooseAll]').click(function() {

if ($('input[@type=checkbox][@checked][@name^=selection]').length)

{

$('span[@id=record_controls1]').show();

}

else

{

$('span[@id=record_controls1]').hide();

}
});
D
Dale author 11/17/2010

I see what your saying about Jquery. I will dig into that.

Just that little bit of code and it displays what I want perfectly.
BUT, yes yet another but, Sergey, I found the code works great on the main list page, but if you have show list on edit page it does not work there.

As the id=chooseALL_1 is now id=chooseALL_2 and id=chooseALL3 for additional lists on the page.
How can I mod that code snippet to make it work with any chooseALL
{ID} and the other numbered $('span[@id=record_controls1]').show(); or $('span[@id=record_controls2]').show(); etc etc.

I have checked on some of my list pages that have 3 mastertable links, and the ID's go up to 6

Sergey Kornilov admin 11/17/2010

You can try the following though I'm not sure if it's going to work well in your setup.

$('span[@id^=record_controls]').hide();
$('input[@type=checkbox][@name^=selection],[@id^=chooseAll]').click(function() {

if ($('input[@type=checkbox][@checked][@name^=selection]').length)

{

$('span[@id^=record_controls]').show();

}

else

{

$('span[@id^=record_controls]').hide();

}
});
D
Dale author 11/17/2010

Thanks Sergey. But the last snippet stopped what was working and had no effect as well on the other lists.

I think I need a piece of code that cylces through all the lists on a page.
Not sure how to do that with jquery.

Again, appreciate the help.

Sergey Kornilov admin 11/18/2010

Actually the latest code sample is supposed to do just that. It uses 'like' search instead of exact control ID to find controls need to be updated.
I would suggest to post your app to demo account and contact support directly. Need to see the whole app in order to provide a better advice.

D
Dale author 11/19/2010

Thanks Sergey, I will give it another go in the morning. Really appreciate it.