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

Provide a way to modify CSS classes on form & elements #17

Open
jonnyhoff opened this issue Jun 9, 2023 · 4 comments
Open

Provide a way to modify CSS classes on form & elements #17

jonnyhoff opened this issue Jun 9, 2023 · 4 comments
Labels
documentation Improvements or additions to documentation

Comments

@jonnyhoff
Copy link

Please provide a way to modify the CSS classes of the form & elements

@carltongibson carltongibson added the documentation Improvements or additions to documentation label Jun 9, 2023
@carltongibson
Copy link
Owner

Hi @jonnyhoff.

CRUDView allows you to specify a form_class:

form_class = None

... and if you need more control, provides both the get_form_class() and get_form() hooks that you can override:

def get_form_class(self):
"""
Returns the form class to use in this view.
"""
if self.form_class is not None:
return self.form_class
if self.model is not None and self.fields is not None:
return model_forms.modelform_factory(self.model, fields=self.fields)
msg = (
"'%s' must either define 'form_class' or both 'model' and "
"'fields', or override 'get_form_class()'"
)
raise ImproperlyConfigured(msg % self.__class__.__name__)
def get_form(self, data=None, files=None, **kwargs):
"""
Returns a form instance.
"""
cls = self.get_form_class()
return cls(data=data, files=files, **kwargs)

Beyond that, you'd customise the form templates as normal.

Anything you're missing there?

@jonnyhoff
Copy link
Author

Hi @carltongibson , Thanks for the prompt response.
Do you have examples of how to use the above or links to docs?

@carltongibson
Copy link
Owner

carltongibson commented Jun 9, 2023

Not yet, but I'll use this ticket to track that. Thanks!

It's no different from what you'd do with Django's views if that helps. (See the docs I linked)

@carltongibson
Copy link
Owner

Also refs #8, which is about providing a Tailwind plugin to style the default Django form markup, in a similar way to the official prose Tailwind plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants