What's new

Welcome to xCrud Community - Data Management and extended PHP CRUD

Join us now to get access to all our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, and so, so much more. It's also quick and totally free, so what are you waiting for?

Problem using xCrud->button() with a condition

Lior Messer

New member
Joined
Dec 9, 2021
Messages
2
Reaction score
0
Points
1
Location
Rio de Janeiro, Brazil
Hi there. I have used xCrud 1.6 quite extensively and am migrating to 1.7.31. I have found an issue with xcrud->button() when using a condition to display (or not) the button

In xCrud 1.6, this is how the screen looks like. Notice that the "G" button only shows in row 8:
1 - xCrud 1_6 (servidor).jpg

Here is a print of my code. This button has a condition where it should only show if the 'calendarid' field is not null
code.png

Now here is a print of the screen with xCrud 1.7.31:
1 - xCrud 1_7 com botão condicional.jpg

Please notice that now there is an empty column (the second one) and the headers are offset with the rows. The header of the second column ('Nome') corresponds to the content in third column. The header of the third column ('Email') corresponds to the content in the fourth column. As so on, with all headers/contents..

My workaround so far it not to use conditions on buttons, which is not the best approach.

Any ideas?
 

dhuerta29

Member
Joined
Dec 10, 2021
Messages
46
Reaction score
1
Points
8
Location
chile
Hi there. I have used xCrud 1.6 quite extensively and am migrating to 1.7.31. I have found an issue with xcrud->button() when using a condition to display (or not) the button

In xCrud 1.6, this is how the screen looks like. Notice that the "G" button only shows in row 8:
View attachment 48

Here is a print of my code. This button has a condition where it should only show if the 'calendarid' field is not null
View attachment 46

Now here is a print of the screen with xCrud 1.7.31:
View attachment 47

Please notice that now there is an empty column (the second one) and the headers are offset with the rows. The header of the second column ('Nome') corresponds to the content in third column. The header of the third column ('Email') corresponds to the content in the fourth column. As so on, with all headers/contents..

My workaround so far it not to use conditions on buttons, which is not the best approach.

Any ideas?
Yes, what you're experiencing looks like a bug/regression in version 1.7.31, not an issue with your code.

Based on the behavior (misaligned headers and an “empty” column), it’s very likely that xCrud is completely skipping the <td> rendering for the button when the condition is not met. This causes some rows to have fewer columns than others, which breaks the table structure.

In earlier versions (like 1.6), it was probably always rendering the cell and only hiding the button content, which is why this issue didn’t occur.

🔧 Workarounds you can try:

  1. Don’t remove the button, just hide it with CSS
    class="<?= $calendarid ? '' : 'd-none' ?>"

  2. Ensure the <td> is always rendered
    Even if the button is not shown, the cell should still exist to keep the table aligned.
  3. Temporarily avoid using conditions in button()
    Not ideal, but it helps confirm the issue is coming from there.
📌 In short: the problem is not the condition itself, but that xCrud is not maintaining a consistent column structure across rows.

You may want to report this as a bug, since it’s clearly inconsistent with the behavior from previous versions.

As a side note, this kind of issue usually happens when visibility logic is mixed with structural rendering. In my own CRUD builder (ArtiGrid), this is handled by always rendering the cell and only toggling the content, which avoids layout breaks entirely.
 

Lior Messer

New member
Joined
Dec 9, 2021
Messages
2
Reaction score
0
Points
1
Location
Rio de Janeiro, Brazil
Hi. Thanks for the comprehensive response. Indeed, it is a bug in xCrud 1.7, rather than an issue with my code. I had already sent this to the xCrud team, actually a month ago and no solution so far... Thay said they would fix it but nothing happened.

This is why I posted it here, so that maybe it gets more visibility and hopefully it is solved.

I am not sure if I can implement your workarounds #1 and #2, this is buried somewhere inside xCrud code and I don't have the time/skill to find it. Actually, I have done exactly what you suggest in workaround #3.

Thanks again, hope they fix it.
 
Top Bottom