Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty column headers in Multiple Forms mobile view #2237 #2239

Merged
merged 3 commits into from
Dec 19, 2024

Conversation

zahardev
Copy link
Contributor

@zahardev zahardev commented Dec 18, 2024

This implements #2237.

💾 Build file (420bd45).

@@ -378,11 +378,8 @@ public function the_field( \GV\Field $field, \GV\Entry $entry ) {
);

if ( $entry->is_multi() ) {
if ( ! $single_entry = $entry->from_field( $field ) ) {
echo '<td></td>';
Copy link
Contributor Author

@zahardev zahardev Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In mobile view, column headers are displayed using the data-label attribute. Here is the default template:

<td id="{{ field_id }}" class="{{ class }}" data-label="{{label_value:data-label}}">{{ value }}</td>

In this particular case we output just <td></td>, with no data-label attribute, and return early. This works fine on the desktop view, but breaks the layout on mobile because it doesn’t have a data-label. I thought about adding the data-label attribute here first, but since labels and entire <td> HTML can be changed later using filters in gravityview_field_output(), it seems better to not return early, and handle this case the usual way for consistency. Please let me know if you'd like to add data-label attribute to instead.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rafaehlers, thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! I saw this comment before, but there wasn't any question.

Please let me know if you'd like to add data-label attribute to instead.

With my simple understanding of the issue, I think that would solve the problem because the CSS to make the table responsive needs that, so yes.

Copy link
Contributor Author

@zahardev zahardev Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrcasual @rafaehlers

Sorry, probably I didn't communicate clearly here. So current change already fixes the issue and works great for me.
Before the fix, empty td looked like this:

<td></td>

After the fix, it looks like this:

<td id="gv-field-18-3" class="gv-field-18-3" data-label="City"></td>

I left this comment just to consider another approach, when we still return early, but add data-label to the early returned <td>. Something like this:

Before:

if ( ! $single_entry = $entry->from_field( $field ) ) {
				echo '<td></td>';
				return;

After:

if ( ! $single_entry = $entry->from_field( $field ) ) {
				printf(  '<td data-label="%s"></td>', $field_label );
				return;

In this case, empty td would look like this:

<td data-label="City"></td>

Both approaches solve the issue, but second one can lead to unexpected bugs in case people use field filters. So I would vote for the current approach ( avoid using early return ).

@zahardev zahardev requested a review from mrcasual December 18, 2024 18:45
@mrcasual mrcasual merged commit d1dd190 into develop Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants