views:

583

answers:

1

Hi, i dont know how ill say this, but i have a Form, in this form im trying to add some fields with jquery (dynamic??) clicking a radio button, so , when im trying the send the data , django said that the fields are empty ... and in the debuger (error pages??) is tru, the fields are empty, but the fields from my Form.py they not.

im new with Django, but i think if the fields are into the the data will send... well Django is a big world.

Form.py

class DiligenciaForm(ModelForm):
""" this is my unhidden form with the radios buttons """

    titulo = forms.CharField(max_length=70,help_text='Dele un nombre a su diligencia.')
    tipo = forms.ChoiceField(choices=TIPO)  
    vias= forms.TypedChoiceField(widget=forms.RadioSelect(), choices=CHOICES)

    class Meta:
        model = Diligencia
        #exclude =('socio','secuencia','ffin','fecha','fentrada','status')
        fields = ('titulo', 'tipo','vias')


#now the hidden form's that i want to render (append) to the first Form

class UnaViaForm(forms.Form):
""" i want with jquery show this form (append to) """
    Desde = forms.CharField(max_length=100)
    Hasta = forms.CharField(max_length=100)

View.py

from diligencia.account.forms import DiligenciaForm, UnaViaForm

@login_required
def test(request):
    form = NuevaDiligenciaForm()
    form_1_via = UnaViaForm()

    return render_to_response('account/vias-form.html', { 'formulario':form,'UnaVia':form_1_via },
                                                           context_instance = RequestContext(request))


well is some weird way: in my template i have this code:

<div id="Una_via"> {{ UnaVia.as_p }} </div> 

and the jquery:
$(document).ready(function(){

   $("#Una_via").css("display","none");

   $("input[name=vias]").click(function(){ 
        var radio = $("input[name='vias']:checked").val();
        if(radio == 1){
            $("#Una_via").show("fast");
        }else{ 
            $("#Una_via").hide("fast"); } 
    });
  });
A: 

Assuming that this form POSTs back to the same view, you are forgetting to bind your forms to the POST data:

def test(request):
    data = request.method == 'POST' and request.POST or None
    form = NuevaDiligenciaForm(data=data)
    form_1_via = UnaViaForm(data=data)
SmileyChris