crispy form tab has twice the same name

Viewed 76

I'm currently using three models:

  • SubBriefe with a foreign key pointing to Briefe
  • SubBriefe has a many to many relationship to SubBriefeField which allows every SubBriefe to point to Subriefefields

the problem is that when I use the layout helper to render my tabs of SubBriefe I have inside Tabs of the SubBriefeFields, the probleme is that if SubBriefeField tab "example" is in both Subbriefe the ID to activate the tab doesn't work as it is present two time,

do you know the function which will make the css.id unique for every tab in my layout helper as I think it already exists for accordion group.

1 Answers

I found the answer you have to go in the Lib\site-packages\crispy_forms\bootstrap.py and copy and paste two methods directecly in forms.py the Tab class and the Container class which you will rename respectively Tabed and Containered in the container init method you change if not self.css.id ... by

self.css.id = f"{self.name}{kwargs['roller']}" and in your new taber you add the argument roller

Taber(name ,Row('', *FieldSet(lister), css_class='col-12'), roller=roller)

and the trick is done, you will have tab within tabs that can have the same name except that we append an argument at the end of the css.id of the tab in case theres repetition,

of course I use the pointer of the main tabs at the end of the css.id so that when i'm in the first tab the subtab end in 0 the second tab -> the subtab end in 1 ....

Related