Here's the onclick event for the delete button link:

onclick="if(confirm(w2p_ajax_confirm_message||'Are you sure you want to 
delete this 
object?')){ajax('/myapp/default/index/delete/mytable/1',[],'');jQuery(this).closest('tr').remove();};return
 
false;"

The problem is when you click delete, it sends an Ajax request to delete 
the record, but it also immediately removes the row from the table 
(regardless of whether the Ajax request is ultimately successful). Perhaps 
instead, it should do:

ajax('/myapp/default/index/delete/mytable/1',[],':eval');

The Ajax call can then return some Javascript that either pops up a message 
indicating the deletion failed (possibly due to it being the last record), 
or if successful, it could delete the row from the table. That would ensure 
the record isn't removed from the table unless it was really deleted from 
the database.

Anthony

On Thursday, May 24, 2012 6:23:58 PM UTC-4, Niphlod wrote:
>
> well, the intended design is NOT to reload page if a row is deleted 
> (better user experience). 
> Small corner cases are "delete every row in the page and be "forced" to 
> click on next page to have new records", etc.....
>
> Anyway, you can intercept delete operations....
>
> deletable = request.vars.stoptoyingaround and False or True
> if request.args(0) == 'delete':
>       if db(db.parameter).count() <= 1:
>           response.flash = 'deleting the last row is not allowed'
>            redirect(URL('yoururl', vars=dict(stoptoyingaround=1)))
>       .......
>
> caveat: if you're using the "args" argument to SQLFORM.grid() 'delete' 
> would be the first arg after the "base" ones.
>
> if you like to have your users to play with the delete button when there 
> is 1 row left (and not harm your database while playing), you can skip the 
> deletable assignement based on request.vars.
> As a nice side effect, you can count your table only when it's needed ;-)
>
>
>

Reply via email to