{"action":"created","issue":{"url":"https://api.github.com/repos/django-crispy-forms/django-crispy-forms/issues/824","repository_url":"https://api.github.com/repos/django-crispy-forms/django-crispy-forms","labels_url":"https://api.github.com/repos/django-crispy-forms/django-crispy-forms/issues/824/labels{/name}","comments_url":"https://api.github.com/repos/django-crispy-forms/django-crispy-forms/issues/824/comments","events_url":"https://api.github.com/repos/django-crispy-forms/django-crispy-forms/issues/824/events","html_url":"https://github.com/django-crispy-forms/django-crispy-forms/issues/824","id":338040422,"node_id":"MDU6SXNzdWUzMzgwNDA0MjI=","number":824,"title":"Question - controlling classes on fields in empty-form with formset","user":{"login":"danizen","id":4966193,"node_id":"MDQ6VXNlcjQ5NjYxOTM=","avatar_url":"https://avatars2.githubusercontent.com/u/4966193?v=4","gravatar_id":"","url":"https://api.github.com/users/danizen","html_url":"https://github.com/danizen","followers_url":"https://api.github.com/users/danizen/followers","following_url":"https://api.github.com/users/danizen/following{/other_user}","gists_url":"https://api.github.com/users/danizen/gists{/gist_id}","starred_url":"https://api.github.com/users/danizen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danizen/subscriptions","organizations_url":"https://api.github.com/users/danizen/orgs","repos_url":"https://api.github.com/users/danizen/repos","events_url":"https://api.github.com/users/danizen/events{/privacy}","received_events_url":"https://api.github.com/users/danizen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-07-03T20:16:55Z","updated_at":"2018-07-03T21:44:30Z","closed_at":null,"author_association":"NONE","body":"* Package version: 1.7.2\r\n* Django version: 1.11.9\r\n* Python version: 3.5.1\r\n* Template pack: bootstrap3\r\n* Template: bootstrap3/table_inline_formset.html\r\n\r\n### Description:\r\n\r\nI am using jquery select2 plugin on some of my longer select/option groups.  Because this is a formset, I implement an add button.   The form has multiple selects in it, and only the first has enough options that it is worthwhile to use select2.   I observe that the djsel2 class is not attached to the selects in the empty-form, and so wonder whether the FormHelper is used when rendering the empty form.\r\n\r\nI have both a Form and a Formset, but only the formset has a helper.\r\n\r\n### Preferably also include:\r\n\r\n* Example Django Crispy Forms code*\r\n\r\n```python\r\nclass IndexingHistoryForm(forms.ModelForm):\r\n    date_of_action = forms.DateField()\r\n\r\n    class Meta:\r\n        model = IndexingHistory\r\n        fields = [\r\n            'citsub',\r\n            'action',\r\n            'date_of_action',\r\n            'input',\r\n            'fully_indexed_yn',\r\n            'coverage',\r\n            'coverage_note',\r\n        ]\r\n\r\nclass IndexingHistoryInline(InlineFormSet):\r\n    model = IndexingHistory\r\n    form_class = IndexingHistoryForm\r\n    fields = [\r\n        'citsub',\r\n        'action',\r\n        'date_of_action',\r\n        'input',\r\n        'fully_indexed_yn',\r\n        'coverage',\r\n        'coverage_note',\r\n    ]\r\n    extra = 0\r\n    prefix = 'ixh'\r\n\r\n    def construct_formset(self):\r\n        formset = super().construct_formset()\r\n        formset.helper = FormHelper()\r\n        formset.helper.form_tag = False\r\n        formset.helper.disable_csrf = True\r\n        formset.helper.template = 'bootstrap3/table_inline_formset.html'\r\n        formset.helper.layout = Layout(\r\n            Field('citsub', css_class='djsel2'),\r\n            'action',\r\n            'date_of_action',\r\n            'input',\r\n            'fully_indexed_yn',\r\n            'coverage',\r\n            'coverage_note',\r\n        )\r\n        return formset\r\n\r\n```\r\n\r\n* JavaScript that runs on the form*\r\n\r\nThis needs some explanation - the form is in a bootstrap modal.    The modalChanged function is run when the html code for the view containing the modal is added to the form, e.g.- initial load and when the modal does not commit successfully.   This is achieved through the query-form plugin.  The modal's response uses status_code 202 or 201 on success, and something else happens.\r\n\r\n```javascript\r\n        /* When the content of the modal changes, re-attach behaviors to it */\r\n        function modalChanged() {\r\n            var datepickConfig = { changeMonth: true, changeYear: true };\r\n            var modal = $('#ixhist');\r\n            modal.find('tbody tr').not('.emtpy-form').find('.djsel2').select2();\r\n            modal.find('tbody tr').not('.empty-form')\r\n                .find('.dateinput').datepicker(datepickConfig).attr('autocomplete', 'off');\r\n            modal.find('button.formset-add').click(function() {\r\n                SEF.addFormSetRow('ixhist', 'ixh');\r\n                /* add select2 to the new row - must select by something else now */\r\n                $('#ixhist tr:last .citsub').select2();\r\n                /* add datepicker to the new row */\r\n                $('#ixhist tr:last .dateinput').removeClass('hasDatepicker');\r\n                $('#ixhist tr:last .dateinput').datepicker(datepickConfig).attr('autocomplete', 'off');\r\n            });\r\n        }\r\n```\r\n\r\n*Screenshot shows the absence of class after the add formset row*\r\n![crispy-forms-select2](https://user-images.githubusercontent.com/4966193/42242480-00dafbd4-7edc-11e8-8e6f-a906782de21b.png)\r\n\r\n*Actual HTML generated*\r\n\r\nFor empty row:\r\n```\r\n<tr class=\"hidden empty-form\"> <td id=\"div_id_ixh-__prefix__-citsub\" class=\"form-group\"> <div class=\"controls \"> <select name=\"ixh-__prefix__-citsub\" id=\"id_ixh-__prefix__-citsub\" class=\"select form-control\"> <option value=\"\" selected=\"\">---------</option> <option value=\"IM\">Index Medicus (IM)</option> <option value=\"S\">NASA (S)</option> <option value=\"AIM\">aim (AIM)</option> <option value=\"B\">Biotech (B)</option> <option value=\"C\">Communication Disorders (C)</option> <option value=\"D\">Dental (D)</option> <option value=\"F\">Non-U.S. Center title (F)</option> <option value=\"H\">Health - AHA (H)</option> <option value=\"K\">Consumer Health (K)</option> <option value=\"N\">Nursing (N)</option> <option value=\"P\">PubMed only (P)</option> <option value=\"R\">Reproduction (R)</option> <option value=\"T\">Health - NICHSR (T)</option> <option value=\"X\">AIDS (X)</option> <option value=\"G\">Genbank Only (G)</option> <option value=\"J\">PIP (J)</option> <option value=\"E\">KIE (E)</option> <option value=\"Q\">HMD (Q)</option> <option value=\"QO\">HMD 0 (QO)</option> <option value=\"HSR\">Health - ECRI (HSR)</option> <option value=\"OM\">OLDMEDLINE (OM)</option> <option value=\"HMA\">HSR - Meeting Abstracts (HMA)</option> <option value=\"MS\">Author (MS)</option> <option value=\"QIS\">HMD - Index Section (QIS)</option> <option value=\"SD\">Selective Deposit (SD)</option> <option value=\"FHKL\">kkkkkkkkk (FHKL)</option> <option value=\"CO\">name (CO)</option> <option value=\"BB\">bb (BB)</option> <option value=\"CC\">cc (CC)</option> <option value=\"SAVE\">save (SAVE)</option> <option value=\"DGH\">hmfd (DGH)</option> <option value=\"CODE\">name (CODE)</option> <option value=\"SACE\">save (SACE)</option> <option value=\"BBBB\">B (BBBB)</option> <option value=\"ME\">name (ME)</option> <option value=\"ZB\">zb (ZB)</option> <option value=\"MSV\">Author Manuscript Veterans Affairs (MSV)</option> <option value=\"MSB\">Author Manuscript EPA (MSB)</option> <option value=\"MSN\">Author Manuscript NIST (MSN)</option> <option value=\"MSF\">Author Manuscript FDA (MSF)</option> <option value=\"MSP\">Author Manuscript ASPR (MSP)</option> <option value=\"MSO\">Author Manuscript Other US Funding Organizations (MSO)</option> <option value=\"AODE\">name (AODE)</option> <option value=\"BBB\">bbbb (BBB)</option> <option value=\"CD\">cccc (CD)</option> <option value=\"EE\">eeee (EE)</option> <option value=\"MSH\">Author Manuscript Department of Homeland Security (MSH)</option>\r\n</select>\r\n# ... other stuff continues on\r\n</tr>\r\n```\r\n\r\n*Expected HTML*\r\n\r\nWant to see the djsel2 class on the select, as in the non-hidden rows.\r\n"},"comment":{"url":"https://api.github.com/repos/django-crispy-forms/django-crispy-forms/issues/comments/402300826","html_url":"https://github.com/django-crispy-forms/django-crispy-forms/issues/824#issuecomment-402300826","issue_url":"https://api.github.com/repos/django-crispy-forms/django-crispy-forms/issues/824","id":402300826,"node_id":"MDEyOklzc3VlQ29tbWVudDQwMjMwMDgyNg==","user":{"login":"danizen","id":4966193,"node_id":"MDQ6VXNlcjQ5NjYxOTM=","avatar_url":"https://avatars2.githubusercontent.com/u/4966193?v=4","gravatar_id":"","url":"https://api.github.com/users/danizen","html_url":"https://github.com/danizen","followers_url":"https://api.github.com/users/danizen/followers","following_url":"https://api.github.com/users/danizen/following{/other_user}","gists_url":"https://api.github.com/users/danizen/gists{/gist_id}","starred_url":"https://api.github.com/users/danizen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danizen/subscriptions","organizations_url":"https://api.github.com/users/danizen/orgs","repos_url":"https://api.github.com/users/danizen/repos","events_url":"https://api.github.com/users/danizen/events{/privacy}","received_events_url":"https://api.github.com/users/danizen/received_events","type":"User","site_admin":false},"created_at":"2018-07-03T21:44:30Z","updated_at":"2018-07-03T21:44:30Z","author_association":"NONE","body":"Changed my formset helper to use a `table_formset.html` template derived from `bootstrap3/inline_table_formset.html`.   Changed it to include `empty_form_field.html` derived from `bootstrap3/field.html`.   Added some markup for css_classes of the fields:\r\n\r\n```html\r\n    <!-- field classes: {{ field.css_classes }} -->\r\n    <{% if tag %}{{ tag }}{% else %}div{% endif %} id=\"div_{{ field.auto_id }}\" {% if not field|is_checkbox %}class=\"form-group{% else %}class=\"checkbox{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if form_show_errors%}{% if field.errors %} has-error{% endif %}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}\">\r\n```\r\n\r\nThe fields in the empty form definitely do not have classes.\r\n"}}
{"actor":{"display_login":"danizen"}}