This topic is locked

Disabling a custom button till some records are selected

6/5/2018 1:28:14 PM
PHPRunner Tips and Tricks
admin

This article applies to PHPRunner, ASPRunner.NET and ASPRunnerPro.
We added a custom button to the list page that copies selected records to another table. We this button to appear disabled till user selects one or more records. To do so we need to figure button's ID.
Build your project and run it in the web browser. In Chrome browser right-click on your button and choose 'Inspect' which shows us the following:


We can see that button's ID starts with "Copy_Selected". We copy this prefix and paste it into our code. The code itself goes to Javascript OnLoad event of List page in question.

var id = "Copy_Selected";

var button = $("[id^=" + id + "]");

Runner.addDisabledClass(button);
$('input[name="selection[]"], input[id^=chooseAll]').change(function() {
var c = $('input[name="selection[]"]:checked').length;

if (c>0)

Runner.delDisabledClass(button);

else

Runner.addDisabledClass(button);

});


This is it. Our button will be enabled as as soon as we select one or more records on the list page.

E
exora 6/6/2018

Hi Sergey,
I have tried this tips and works fine when I select one or more records. But it doesn't work when I select all.

V
veca 6/10/2018



Hi Sergey,
I have tried this tips and works fine when I select one or more records. But it doesn't work when I select all.


Try ":checkbox" as selector.
$(':checkbox').change(function() {
var c = $('input[name="selection[]"]:checked').length;
if (c>0)

Runner.delDisabledClass(button);

else

Runner.addDisabledClass(button);
});