[SOLVED] PHP run buttons on grids don't detect anymore if no rows are selected

As of 8.1.030 (but maybe even earlier) PHP run buttons are broken: they execute their code even when no rows are selected in the grid!

Details and one more user confirming the bug are here:

PHP run buttons on grids don’t detect anymore if no rows are selected

​@John_L_Santos / @Artur_Oliveira

​I can confirm this error! It’s broken since .029 or .030.

@RHS thanks for checkin

Can you please check also the other issue I’m having with PHP run buttons on grids with nested grids?:

Don’t remember the old behaviour. But IMHO, if now executes without selected rows, it’s a feature for me, not an error.

@ Giu

you can check the “old” and IMHO correct behavior in this online sample by NetMake.
Click on the “Process” button in the header of this grid, without first selecting any row in the grid, and you’ll get prompted to “Select data” (so run code is not executed):
http://www.scriptcase.net/scriptcase…rds-of-a-grid/

On newly compiled grids that alert won’t be shown anymore.

What’s the point of having the run button run on no records?

What happens is that the onFinish code only is actually executed, but the expected behavior is that nothing should be executed.

I think I’ve found the bug in the SC generated JS code.
Below is the beginning of the JS function generated by SC 8.1.030 for a PHP run button I called “mass_delete”;
I copied that function and the UI checkboxes in a test environment.
If I remove the equal sign marked in red, everything works as expected: when no checkboxes are selected the alert ‘Select data’ is shown and the function returns without processing the rest of the code.
Please NetMake: fix your generator code.

    

   function sc_btn_mass_delete()
   {
       var vls_check = "", checked_records, i;
       checked_records = $(".sc-ui-check-run").filter(":checked");
       for (i = 0; i <[B]=[/B] checked_records.length; i++)
       {
           vls_check += (vls_check != "") ? ";" : "";
           vls_check += $(checked_records[i]).val();
       }
       if (vls_check == "" || vls_check == "0")
       {
           alert ("Select data");
           return;
       }
...

You can have a button thath needs to execute globally or only to checked records. Old, you need 2 buttons. Now 1. You just have add an if in your onfinish. Is totally better now.

Sorry, I’m from mobile.

Giu, sorry but I don’t get what you mean.
Is this a documented change (where?) or something you think it is an on purpose change and not a bug?

To me it’s clearly a bug, as I’ve shown in the post where I included the new JS code from NetMake: the alert “Select data” is still there, but it will never fire because of the mistake they made in the code in the for loop.

Also note that because of this bug, I think that when you select some records, the onRecord loop will be executed +1 times that the amount of records you selected.
That’s why even on zero records it will be run once (0 selected records +1 extra loop due to the bug = 1)
You’ll likely not notice any effect, but only because on this extra loop you won’t be able to retrieve any records data as the values will be empty.

I think that if NetMake wants to change the behavior of the PHP run button, they should:

  1. write it in the changelog so that we are aware of the change (is it and I just haven’t noticed it?)
  2. make it in a reliable way

What I tried to explain is…the new behaviour has more sense for me, then yes, it’s a “bug” because it works differently than before, but for me is more interesting now, then… for me, it’s not a bug, but a feature.

Also note that because of this bug, I think that when you select some records, the onRecord loop will be executed +1 times that the amount of records you selected.
That’s why even on zero records it will be run once (0 selected records +1 extra loop due to the bug = 1)
You’ll likely not notice any effect, but only because on this extra loop you won’t be able to retrieve any records data as the values will be empty.

Don’t know, I didn’t tried, but is fast to check of how many times onRecord is fired.

But yes, obviously, “fixed” as a bug or new feature, should be clear in changelog and not as this:

ScriptCase v8.0.028 - 01-21-2015 22:53
Fixed Javascript problem when using the Run button.

Fixed in 8.1.031

Thanks NetMake.

Sadly. For me was interesting. As mentioned, more a feature than a bug

Can anyone confirm the fix is still working?
I’m now on [SIZE=12px]8.1.038 and it looks like the bug is back.[/SIZE]