Monday, March 30, 2015

Re: Help with Dynamically Adding Forms to Formset!!

Thank you, Bill. That was silly of me. I'm just confused on where/how those actual links are displayed. I can't get them to show...


{% load crispy_forms_tags %}
<script src="{{ STATIC_URL }}js/addAuthor.js" type="text/javascript"></script>
<script src="{{ STATIC_URL }}js/jquery.formset.js"></script>
<script type="text/javascript">
    $(function() {
        $('#authorFormset .formset').formset({
            prefix: '{{ formset.prefix }}',
            addText: 'Add Author',
            deleteText: 'Remove Author',
        })
    })
</script>

<form action="{% url 'data:register' %}" method="post" enctype="multipart/form-data">


  <div class="container">
    <div class="row" style="margin-top: 30px">
      <div class="col-md-10 col-md-offset-1">
        {{ dataset_form.media }}
        {% crispy dataset_form %}
        {% crispy facility_form %}
        {% crispy contact_form %}
       
        <div id="authorFormset" class="formset">
        {% for form in formset.forms %}
            <div class="formset">
                <div id="{{ form.prefix }}-row">
                    <div class="col-md-2">
                        <div class="row">
                            {{ form.first_name }}
                        </div>
                        <div class="row">
                            {{ form.last_name }}
                        </div>
                    </div>
                    <div class="col-md-4 col-md-offset-1">
                        <div class="row">
                            {{ form.email }}
                        </div>
                        <div class="row">
                            {{ form.role }}
                        </div>
                    </div>
                </div>
            </div>
        {% endfor %}
        {{ formset.management_form }}
        <br><br>
    </div>
  
      </div>
    </div>
  </div>

  <div class="container">
    <div class="row">
      <div class="col-md-10 col-md-offset-1">
        <a role="button" class="btn btn-lg btn-default" href="{% url 'data:data_home' %}">Cancel</a>
        <input type="submit" class="btn btn-lg btn-success pull-right" value="Proceed to Data Upload">
      </div>
    </div>
  </div>
</form>

On Mon, Mar 30, 2015 at 6:31 PM, Bill Blanchard <bill.blanchard@gmail.com> wrote:

Hi Stephanie,
The addText and deleteText variables are the hyperlink text that is displayed on the page.

You can remove them or modify accordingly. I believe the default values are Add Form and Remove Form if you do not explicitly declare them in the javascript function.

On Mar 30, 2015 6:03 PM, "Stephanie Socias" <stephsocias@gmail.com> wrote:
Thank you all SO much for your advice. Even just hearing that this is a complicated problem and that it's not just me, really helps.

I will post my code shortly. I'm now trying to incorporate some of your feedback.

Bill,
How do I set/use the 'addText' and 'deleteText' variables from the script in the template? That is probably a really dumb question but I have just about zero experience with javascript/jquery.

Thank you!
Stephanie

On Mon, Mar 30, 2015 at 5:18 PM, Carl Meyer <carl@oddbird.net> wrote:
Hi Stephanie,

On 03/30/2015 02:37 PM, Stephanie Socias wrote:
> I'm having trouble creating a formset where I can dynamically add and
> delete items. I've tried many different approaches and can't get
> anything to work. I'm new to Django and have been at this for days. Can
> someone please help me!? I can send my code, post it, or do a screen
> share. Please let me know!! Any help would be greatly appreciated.

I'm afraid I don't have time in my day for a screen-share, but I'd be
happy to try to help, if you can link to a gist or paste showing your
current best effort, and explaining how it is not working.

FWIW, I've usually used this library for the JavaScript side of things:
https://github.com/jgerigmeyer/jquery-django-superformset

If you'd find real-time assistance more helpful, you could visit the
#django channel on FreeNode IRC; I and others are available to help out
there.

This is a challenging task you've tackled, even for experienced Django
developers, so it's not surprising that it's taking some time if you're
new to Django.

Carl

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/3UR_6HtcnY0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5519BD9B.9080105%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOw%3DD6XQnVp%3Dd1EdvgEPxL_N5w%3D2eKm_4nXF9KHN_zAaH1bTew%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/3UR_6HtcnY0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAP7uEDLKxMwiU%2BtMBuZBcjPiEjGXR-JGhn2UOKtik0ibK2NRmw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOw%3DD6V45R64%3D0o2W9miXJzy_xqBW5YLooTS7ef9DzNuPATxiQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment