iommirocks / iommi

Your first pick for a django power cord
http://iommi.rocks
BSD 3-Clause "New" or "Revised" License
718 stars 47 forks source link

[Bug] Image field required during upload in spite of using a conditional __required with a lambda function #554

Open akhileshThapliyal opened 1 month ago

akhileshThapliyal commented 1 month ago

I have a scenario where I want to prompt users to upload their profile picture in create mode. Once the user uploads a profile picture and edits the other form fields such as country etc.. it should allow the form validation to pass without making the profile picture field mandatory.

Expectation is based on the condition below it should only make the field mandatory on create, and on edit, it should allow to pass the form validation for the profile picture field without the need to re-upload it, as the details are already present in the form.

Django + Iommi Playground: https://github.com/akhileshThapliyal/django_plaground

onCreate

image

onEdit

image

Profile Image Field Configuration

fields__profile_image=Field.image(
    template='user_app/profile_image_row.html',
    input__attrs={
        "id": "image-file-upload",
        "class": {
            "d-none": True
        }
    },
    required=lambda form, **_: form.instance is None
 )