-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Fixes #14 -- Added Float Field #42
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, that is working for me. It is a shame that placeholder text can't be overridden.
I tried the following in the field file.
def __init__(self, *args, **kwargs):
breakpoint()
super().__init__(*args, **kwargs)
self.attrs["placeholder"] = kwargs.get('placeholder', self.fields[0])
in the form I define the field as
FloatingField('email', css_class="mb3", placeholder="Email Here")
This sets the self.attrs["placeholder"] to 'Email Here. Unfortunately, the whole mechanism of bootstrap5's floating fields is to present the floating label as the placeholder text, until input. Ah well. Just to note, really, that you can set the placeholder text to anything you want in the field, and it will be set to the value of 'label'.
So, worth mentioning in the docs, I guess, that floating fields don't have placeholder text.
EDIT
I have just tried defining a label for the field in the form meta class and it doesn't show up. However, it does when I define the following in my form init,
self.fields['email'].label = "Email Here!"
self.helper.layout = Layout(.....
It also works in the case where I define a field with a label in the form itself ie:
username = forms.CharField(label="Your username here!")
please keep in mind that I am testing against bootstrap4 crispy errors_and_help_text code. As soon as I get a mo, probably tomorrow, I will make a new branch for my code base, and try migrating to crispy bootstrap 5, and will test this again then.
@millerthegorilla -- anything else to add here? If not I'll write up a small documentation note -- probably to the readme -- and look to merge this. |
I will take a look first thing tomorrow, but I still haven't got round to switching my project to crispy bs5 yet. |
Perfect! Looking forward to merge this. |
@eriktelepovsky Have you given this a run? Do you think the way this would be used in forms is right? |
Hi, sorry I got snowed under. I just checked this and it looks really good, and works well, at first glance. Looking forward to it being merged. |
Just one thing I notice straight away, probably me not getting it straight, but there are a few floating fields in a form, that have the following html below them - |
Ok, I had some spurious help_text defined. The only issue that I can see is that when I have help_text defined in the model rather than the form, it is not showing in the rendered html. |
Ok, let's merge this. Thanks all for your input.
This sounds like a separate issue, I'm not sure without taking a closer look |
e7aadd8
to
a50d0f6
Compare
I haven't tested selects, but it also works fine with textareas which is nice. |
@smithdc1 is there any reason this can't be merged? I am hoping to roll out my crispy forms bootstrap5 site, with the funky new floatfields! |
Ok, I added additional tests for failing fields, text area and selects. All seem to look ok to me. 🙂 |
@millerthegorilla -- here's a draft implementation for floating fields. Do you want to take a look?
The test shows how this would be used. Is this the right way of doing this? 🤔