django-cms / django-filer

File and Image Management Application for django
https://django-filer.readthedocs.io/
Other
1.76k stars 577 forks source link

Multiply widgets are not distinguish #315

Closed miguelramos closed 2 years ago

miguelramos commented 11 years ago

If i use the widget as example on a comment group, multiply widgets are not distinguish when you select an image. You have 20 comments and a possibility too comment and attach a file, when you select an image the script always result send you for the first field of this 20 comments. Have you guys tried this? Which is the javascript that control this behavior?

Regards!

stefanfoulis commented 11 years ago

that is weird. At least in a inline fieldset in admin it seems to work fine with multiple image fields on one page.

What version of django-filer are you using? Are you sure all form fields have different names?

The JS code that populates the form field with the selected image id is here

miguelramos commented 11 years ago

I'm using 0.9.4. And just to be more clear here it is what i'm done. I'm using together with mptt.

file: model.py
class RoadRevision(MPTTModel):
    road = models.ForeignKey(Road, verbose_name=_('road'))
    priority = models.ForeignKey(Priority, verbose_name=_('priority'))
    revision = models.IntegerField(editable=False, default=0)
    comment = models.TextField(verbose_name=_('comment'))
    author = models.IntegerField(verbose_name=_('author'), editable=False)
    attach = FilerFileField(null=True, blank=True, verbose_name=_('attachments'))
    updated_at = models.DateTimeField(auto_now=True)
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')

file: form.py
class RevisionCommentForm(forms.ModelForm):

    class Meta:
        model = RoadRevision
        exclude = ['updated_at']
        widgets = {
            'road': forms.HiddenInput(attrs={'value': ''}),
            'parent': forms.HiddenInput()
        }

    class Media:
        js = ('admin/js/core.js', 'admin/js/admin/RelatedObjectLookup.js',
              'admin/js/jquery.js', 'admin/js/jquery.init.js', 'admin/js/actions.js', 'filer/js/popup_handling.js')

template: html
{% recursetree revisions %}
 <div id="c-{{ node.id }}" class="collapse">
     <form action="{{ request.get_full_path }}" enctype="multipart/form-data" method="post" class="form-horizontal">
         {% csrf_token %}
             {% for field in form.visible_fields %}
             {{ field.errors }}
             {{ field.label_tag }}
             {{ field }}
         {% endfor %}
         {% for hidden in form.hidden_fields %}
             {% if hidden.html_name != 'parent' %}
             {{ hidden }}
             {% endif %}
         {% endfor %}
         <input type="hidden" name="parent" id="id_parent" value="{{ node.id }}">
         <button type="submit" class="btn btn-primary">{% trans "Save" %}</button>
     </form>
 </div>
{% endrecursetree %}

And yes, all fields have the same name, in this case the id is repeat on all fields (id_attach). There is some way to change this behavior? I saw that in template the ids are assumed by the name field.

Regards.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

This will now be closed due to inactivity, but feel free to reopen it.