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

Override Default Input Styles #58

Open
M2Industries opened this issue Oct 11, 2020 · 8 comments
Open

Override Default Input Styles #58

M2Industries opened this issue Oct 11, 2020 · 8 comments

Comments

@M2Industries
Copy link

For stacked forms the inputs in the Field attribute need to take in custom css styles. I noticed that the base_inputs are not overridden for this instance. It would also be nice to get rid of the default mb-3 when custom styles are needed.

Screen Shot 2020-10-11 at 11 16 39 AM

Screen Shot 2020-10-11 at 11 17 03 AM

@smithdc1
Copy link
Member

Hi -- Thanks for the feedback. I'm super excited to have the first issue against this project!

With work and family commitments this week it may be a short while before I get to look at this deeply. In the meantime, just to check my gut reaction, does wrapper_class on the Field give you what you need here? 🤔

https://django-crispy-forms.readthedocs.io/en/latest/layouts.html?highlight=wrapper_class#universal-layout-objects

I can't send a specific link - but search for wrapper_class on this page.

@M2Industries
Copy link
Author

M2Industries commented Oct 11, 2020 via email

@smithdc1
Copy link
Member

Sorry. I focused too much on the comment about the mb-3.

I agree with your point about being able to customise the styles.

I have created a class CSSContainer to hold these customised classes which can be added to the helper. If it's not added the default styles are used.

Although I've not yet got round to documenting this and I'm not sure if this is the best approach and so would value your thoughts.

The benefit here is that the classes can be added once at the helper lever (via css_container). In the example you have had two write the classes out twice which is a bit verbose (and introduce risk of getting it wrong) especially with tailwind being a utility Framework.

https://www.github.com/django-crispy-forms/crispy-tailwind/tree/master/crispy_tailwind%2Ftailwind.py

@smithdc1
Copy link
Member

See #61 for my first draft of what I was thinking...

@M2Industries
Copy link
Author

what i did was simply remove the base_input styles and then add them in the helper. But yes! I think what you described is exactly what i was going for. Since tailwind is utility first I didnt mind not having base styles. It may deter users from using the form helper properly

If custom styles for a Field element are not supplied in the form helper then use the default "base_input" styles:

under CrispyTailwindFieldNode:
base_input = (
# "bg-white focus:outline-none border border-gray-300 rounded-lg py-2 px-4 block w-full "
# "appearance-none leading-normal text-gray-700"
""
)

@Nielssie
Copy link

The benefit here is that the classes can be added once at the helper lever (via css_container).

Hello @smithdc1 Do you have an example how to do this. I can't figure it out. My goals is to give the checkboxselectmultiple a set of classes

@sheckathorne
Copy link

Hey guys, I read the discussion and read through the helpful docs in #61 , however overriding the default_styles still won't let me clear the mb-3 classes showing up in my form.

It looks like the templates are expecting a field_class attribute that I'm not sure how to set in my LayoutHelper:
<div class="{% if field_class %}{{ field_class }}{% else %}mb-3{% endif %}"{% if flat_attrs %} {{ flat_attrs|safe }}{% endif %}>

Any direction you can give is greatly appreciated!

-Sean

@sheckathorne
Copy link

For anyone else struggling with this issue, I ended up copying the field.html template to my project i.e. "templates > tailwind > field.html" and deleting the string instances of "mb-3" which has temporarily solved my problem. Would propose removing these mb-3 classes from the templates since there is no clear way to specify "field_class" when defining fields in Layout.

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

No branches or pull requests

4 participants