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 | Unable to set post handlers #550

Closed akhileshThapliyal closed 1 month ago

akhileshThapliyal commented 1 month ago

I am trying to set the post_handlers for my action buttons, but it doesn't work. For some reason it doesn't override the post handler nor can I assign any post handlers to my custom button on the forms. Please advise. thank you.

ProfileInfoForm = Form.create(
    auto__model=ProfileInfo,
    actions__submit__include=False,
    fields__profile_image=Field.hidden(),
    fields__user__include=False,
    title=None,
    # attrs__id="profile_info_form",
    # attrs__action=reverse_lazy("user:save_profile_info"),
    actions__cancel=Action.button(
        display_name='Cancel',
        attrs__class={
            "btn btn-light btn-default btn-squared fw-400 text-capitalize radius-md "
            "btn-sm": True,
            "btn-secondary": False
        }
    ),
    actions__save_next=Action.submit(
        display_name='Save & Next',
        attrs={
            "class": {
                "btn btn-primary btn-default btn-squared text-capitalize radius-md shadow2 "
                "btn-sm": True,
                "btn-secondary": False
            },
            "type": "submit"
        },
        post_handler=on_akhilesh
    )
)
def on_akhilesh(form, **_):
    print("***********Check if form is valid*********")
    exit()
boxed commented 1 month ago

I did this test on my own code base:


def test(form, **_):
    asd()

new = Form.create(
    auto__model=Customer,
    fields__name__include=False,
    actions__save_next=Action.submit(
        display_name='foo',
        post_handler=test,
    )
)

and when I click the "foo" button I get the crash due to asd not existing like I expect. Is there maybe some extra configuration in the Style you aren't showing?