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

Tabbed Fieldsets/Inlines - Highlight tab button with errors #287

Closed
nattyg93 opened this issue Jun 2, 2023 · 13 comments
Closed

Tabbed Fieldsets/Inlines - Highlight tab button with errors #287

nattyg93 opened this issue Jun 2, 2023 · 13 comments
Assignees
Labels
enhancement New feature or request

Comments

@nattyg93
Copy link

nattyg93 commented Jun 2, 2023

Hi folks,

Love this package and loving the tabbed fieldsets & inlines.

One issue we have encountered is that if there are errors in a different tab, it is very tricky to know where the error is.

Would it be possible to add a class (and styling) to highlight the tab with errors in red?

@nattyg93 nattyg93 added the enhancement New feature or request label Jun 2, 2023
@fabiocaccamo
Copy link
Owner

@nattyg93 thank you for this suggestion, it seems very useful.

@PevznerDanill
Copy link

can anyone duplicate here the suggestion of @nattyg93 mentioned earlier?

@EricPobot
Copy link

EricPobot commented Jul 17, 2024

I managed to implemented it the following way :

  • override the admin/change_form.html template
  • add the following to it :
{% block extrastyle %}
    {{ block.super }}
      .tabbed-changeform-tablink.error {
          color: red !important;
      }
{% endblock %}

{% block footer %}
    {{ block.super }}
    <script>
        document.querySelectorAll(".errors").forEach((elt) => {
            const tabContent = elt.closest(".tabbed-changeform-tabcontent");
            if (tabContent) {
                const tabName = tabContent.id.replace("tabcontent-", "");
                const tabElt = document.getElementById(`tablink-${tabName}`);
                if (tabElt) {
                    tabElt.classList.add('error');
                }
            }
        });
    </script>
{% endblock %}

It works in a quite straightforward way, by looking for tabs containing fields flagged with errors and then styling the tab button with the matching name accordingly. Having several errors in the same tab does not harm since classList.add() doesn't create duplicates.

As for as I could use this snippet, it seems to work fine without any noticeable side-effect.

Feel free to adapt and integrate it in a future version.

@fabiocaccamo
Copy link
Owner

@EricPobot thank you very much for sharing your solution!

@EricPobot
Copy link

I've done a couple of adaptations to the change template for a better support of form rows with multiple fields and associated errors display (among other details).

Since I've not done any extensive testing outside the presentation goals I was aiming, I can't be sure they don't break something. Would you be interested in me sharing them too ?

@fabiocaccamo
Copy link
Owner

@EricPobot indeed!

@fabiocaccamo
Copy link
Owner

@EricPobot I think this could be easily achieved using CSS :has() selector only.

@EricPobot
Copy link

@fabiocaccamo I'm not sure to understand what you are referring to exactly. Could you elaborate please ?

@fabiocaccamo
Copy link
Owner

I managed to implemented it the following way :

- override the `admin/change_form.html` template

- add the following to it :
{% block extrastyle %}
    {{ block.super }}
      .tabbed-changeform-tablink.error {
          color: red !important;
      }
{% endblock %}

{% block footer %}
    {{ block.super }}
    <script>
        document.querySelectorAll(".errors").forEach((elt) => {
            const tabContent = elt.closest(".tabbed-changeform-tabcontent");
            if (tabContent) {
                const tabName = tabContent.id.replace("tabcontent-", "");
                const tabElt = document.getElementById(`tablink-${tabName}`);
                if (tabElt) {
                    tabElt.classList.add('error');
                }
            }
        });
    </script>
{% endblock %}

It works in a quite straightforward way, by looking for tabs containing fields flagged with errors and then styling the tab button with the matching name accordingly. Having several errors in the same tab does not harm since classList.add() doesn't create duplicates.

As for as I could use this snippet, it seems to work fine without any noticeable side-effect.

Feel free to adapt and integrate it in a future version.

I was referring to your solution, but looking closer at the html code it is not possible to do it using the :has() CSS selector only.

@EricPobot
Copy link

Thanks for the clarification. At the end of the day, my proposal seems still valid if I understand correctly your very last message. Am I right ?

@fabiocaccamo
Copy link
Owner

@EricPobot yes it seems valid to me, I'll try to implement it tomorrow.

@EricPobot
Copy link

Nice. Glad to have been able to contribute... at a very small scale obviously :)

@fabiocaccamo
Copy link
Owner

@nattyg93 @PevznerDanill @EricPobot fixed in 0.29.2 version.

@EricPobot thank you again for your useful snippet.

@github-project-automation github-project-automation bot moved this from Todo to Done in Open Source Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

4 participants