0

I've defined the form as follows:

form = crud.update(db.table, table_id, next=URL('nextpage'))
crud.settings.update_onaccept = myfunction()

I need to call myfunction() again after the form is submitted, but before the nextpage is loaded. Is there a crud setting that I can set that will call a function after the form has been submitted?

  • It looks weird that you're calling the function here. I think it should be something like: `sl = StorageList(); crud.settings.update_onaccept = sl; sl.append(myfunction)` – mgilson Feb 19 '16 at 00:31
  • I'm not sure I understand why I need to use StorageList? @mgilson – tannermkerr Feb 19 '16 at 01:08
  • I don't know either -- Just everything I found in the internet seemed to be using `StorageList`. You could try it without calling the function: `crud.settings.update_onaccept = myfunction` – mgilson Feb 19 '16 at 01:10
  • No need to create an empty `StorageList`, as `crud.settings.update_onaccept` is initialized as an empty `StorageList`. In fact, it can simply be a regular Python dictionary (with table names as keys), list, or tuple, or just a single function. – Anthony Feb 19 '16 at 03:05

1 Answers1

0

You should not do:

crud.settings.update_onaccept = myfunction()

as you are calling myfunction right there, when you really just want to register it as a callback to be used later. Instead, use:

crud.settings.update_onaccept.tablename.append(myfunction)

Now, after the update has been accepted and applied, myfunction will be called, and the Crud Form object will be passed to it.

Note, if there is only one callback, you can also just do:

crud.settings.update_onaccept.tablename = myfunction

as there is no need to append to an existing list of callbacks.

Finally, if you want to use the same callback for all database tables (or are only using Crud for a single table), you can just do:

crud.settings.update_onaccept = myfunction
Anthony
  • 25,466
  • 3
  • 28
  • 57