eldarion / eldarion-ajax

a library for adding declarative ajax functionality to your website
BSD 3-Clause "New" or "Revised" License
758 stars 153 forks source link

Noob question (forms) #30

Closed xsanch closed 11 years ago

xsanch commented 11 years ago

Hi,

i am trying to extend your demo with another field in the form but unfortunately I am not getting anything to Django:

    <form class="form-inline ajax" method="post" action="{% url task_add %}" data-append="#tasks">
        {% csrf_token %}
        <div class="input-append">
            <input type="text" class="span4" name="label" placeholder="Enter a stream name...">
        </div>

        <div class="input-append">
            <input type="text" class="span4" name="phonenumber" placeholder="Enter a phonenumber...">
        </div>
    </form>

Added the phonenumber field:

views.py:

    @require_POST
    def add(request):
        session = Session.objects.get(session_key=request.session.session_key)
        if Task.objects.filter(label__exact=request.POST.get("label")).exists():
          data = _task_data(request,Task.objects.get(label__exact=request.POST.get("label")),True)
          return HttpResponse(json.dumps(data), mimetype="application/json")
        task = Task.objects.create(
            session=session,
            label=request.POST.get("label"),
            phonenumber=request.POST.get("phonenumber")
        )
        data = _task_data(request, task)
        return HttpResponse(json.dumps(data), mimetype="application/json")

models.py:

    class Task(models.Model):
        session = models.ForeignKey(Session)
        label = models.CharField(max_length=100)
        done = models.BooleanField(default=False)
        phonenumber = models.CharField(max_length=10)

I am sorry but I am really new to django / ajax.

NamPNQ commented 11 years ago

You can check in function _task_data(request,task)

paltman commented 11 years ago

@xsanch i am not really following your question or what you are wanting to accomplish. Can you elaborate?

paltman commented 11 years ago

@xsanch Has the new eldarion-ajax release solved this for you? I really don't understand the problem you are seeing. Can you provide some more details?

paltman commented 11 years ago

@xsanch i am going to close this for now. please send another issue if you are still having problems.