GithubHelp home page GithubHelp logo

Comments (3)

gregmuellegger avatar gregmuellegger commented on May 26, 2024

The problem here is that the hidden widget and a non-hidden widget (HiddenMapInput in your example) are two separate things. And it's not trivial to get from the one to the other. Imagine a <select> widget that requires totally different attributes than a <input type="hidden" />. Maybe it would be good to have a construct_hidden_widget method on the form field? That would solve the problem since you could control the hidden widget entirely from there. But then we would also need to modify the BoundField class slightly which don't do yet.

It might still be worth thinking about..

from django-floppyforms.

mbaechtold avatar mbaechtold commented on May 26, 2024

@gregmuellegger I don't see why HiddenMapInput would not be a hidden widget since it inherits from HiddenInput?

I just stumbled upon the same problem and I can only repeat what @adys said with the following example:

import floppyforms as forms

class MyForm(forms.Form):
    my_field = forms.CharField(widget=forms.HiddenInput(attrs={'ng-model': 'form.my_field'}))

The execution of {{ field.as_hidden }} in templates/floppyforms/rows/p.html then causes the field not to render the "attrs" because the "attrs" are not passed to django.forms.BoundField.as_hidden().

Am I missing something?

from django-floppyforms.

gregmuellegger avatar gregmuellegger commented on May 26, 2024

I see that this might be non-intuitive. But it is exactly the same behaviour that Django shows.

When using Django 1.7:

>>> from django import forms
>>> class MyForm(forms.Form):
...     my_field = forms.CharField(widget=forms.HiddenInput(attrs={'ng-model': 'form.my_field'}))
...
...
>>> form = MyForm()
>>> print form['my_field']
<input id="id_my_field" name="my_field" ng-model="form.my_field" type="hidden" />
>>> print form['my_field'].as_hidden()
<input id="id_my_field" name="my_field" type="hidden" />

And when using django-floppyforms 1.3.0:

>>> import floppyforms as forms
>>> class MyForm(forms.Form):
...     my_field = forms.CharField(widget=forms.HiddenInput(attrs={'ng-model': 'form.my_field'}))
...
...
>>> form = MyForm()
>>> print form['my_field']
<input type="hidden" name="my_field" required ng-model="form.my_field" id="id_my_field">

>>> print form['my_field'].as_hidden()
<input type="hidden" name="my_field" id="id_my_field">

I think django-floppyforms should only replicate Django's behaviour as good
as possible. After all it is design as a drop-in replacement. So I'm sorry for
closing this as a won't-fix as I see your point.

Maybe that is something that you would like to address in Django core?

from django-floppyforms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.