Comments (6)
Thanks for the report... Right now the input types problem can be avoided by passing a widget class in the form field definition:
class SomeForm(forms.Form): number = forms.DecimalField(widget=forms.TextInput)
Or by overriding the form's init method:
class SomeForm(forms.Form): number = forms.DecimalField() def __init__(self, *args, **kwargs): super(SomeForm, self).__init__(*args, **kwargs) self.fields['number'].widget.input_type = 'text'
There could also be a global switch in the settings but I'm not in favor of 1) introducing a floppyforms-specific setting and 2) having a different output depending on the value of a setting.
Also, the current output is HTML, not XHTML like the current behaviour in Django itself.
A decision probably needs to be made. Should floppyforms behave exactly like Django or take some distance? I agree lots of HTML5 browser controls aren't even usable now (the chrome datepicker for instance) but I found it cool to already support them. Also, if we adopt Django's current behaviour, should the "email" and "url" input types be disabled as well?
If floppyforms or a similar template-based widget system gets added to Django itself (I'll make a proposal for django 1.4), backwards compatibility becomes an issue. The fact that it's a separate library lets us take some distance, as long as this distance remains reasonable and HTML5-related issues can be solved relatively easily.
I'd rather keep the current behaviour since it's being used and documented but it's not a very strong opinion, let me know what you think...
from django-floppyforms.
I'm opening these points as issues but really I'm mostly just trying to start conversations about the design decisions. I'm definitely willing to help you get this into 1.4 as I think it is the right direction.
I think the html5 syntax is acceptable (and by this I mean using non-closing tags for example) for most developers. However, I feel like the input types trigger functionality that often may or may not be wanted on a per-field or per-application basis.
Perhaps something like:
class SomeForm(forms.Form):
number = forms.DecimalField(input_type="text")
The issue is if you are using ModelForms. I was originally thinking of having an overridable compatibility setting put into the context and then have:
<input {% if compat %}type="{{ type }}"{% endif %} ...
I can see how that might be annoying for people who wish to modify the templates. Another option would be to set the type
in the widget class based on the setting. I can see it coming up as an issue for people so perhaps the solution is to simply document it.
from django-floppyforms.
I agree with you about the input type thing but I'd really love not to introduce complexity that would get in the way of people willing to have the "new" input types.
In django there is a clear separation between a form field (handling data validation and coercing) and a form widget (rendering an <input>
with the value in it). The syntax you're suggesting (DecimalField(input_type="text")
would introduce a coupling between the fields and the widgets API. Plus, we're already messing with widgets rendering so I'd love not to mess with the fields API :).
I'm not sure what you mean by "the issue is if you are using ModelForms".
For a start I'll add a section to the docs: "I'm already using django forms, what happens exactly if I switch to floppyforms?". There could be a detailed description of the differences and we can document how to get strictly django's behaviour. I'll try to give it a go this week.
from django-floppyforms.
I finally added that section. If you see anything that can be improved, let me know!
http://django-floppyforms.readthedocs.org/en/latest/differences.html
(not sure what to do with the issue though :)
from django-floppyforms.
I think that definitely helps. I'll close this issue. If either of us come up with a better way to switch the forms fields on a case by case basis, we can revisit it. Thank you!
from django-floppyforms.
I'm definitely considering the addition of a formfield_callback [0] for a floppyforms-flavoured ModelForm
. I'd rather enabled it directly in the default ModelForm for consistency, this way you get only floppyforms with no extra syntax and not a mix of different libraries.
from django-floppyforms.
Related Issues (20)
- How to use bootstrap style to `datalist`?!
- gis warning when I don't want to use gis HOT 5
- TypeError: get_context() got an unexpected keyword argument 'renderer' on Django 1.11.3 HOT 27
- VariableDoesNotExist: Failed lookup for key [help_text] in u'iban' HOT 1
- Custom radioselect required attrs Widget or rendered? HOT 1
- Endless Loop with django-debug-toolbar HOT 2
- the image_thumbnail.html example causes an error when image exist HOT 3
- Django 2.1 update causing for error, renderer() HOT 4
- Widgets not rendering extra attrs HOT 2
- Removed ORGException causes issues when using GeoDjango after 2.0 HOT 1
- Prepare 1.8.0 release
- Implement Jazzband guidelines for project django-floppyforms HOT 4
- [1.8.0 release blocker] Django templates breaking change? HOT 1
- GeoDjango widgets in admin site cannot be used as regular widgets with the Meta widgets attribute HOT 3
- Django 3 'six' incompatability HOT 2
- Is this project dead? HOT 7
- geodjango floppyform issue
- set extent of map using map_options HOT 3
- How to filter widget input datalist with user name
- Drop support for Python 3.6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-floppyforms.