a possible solution
# controller
def update_record():
form = crud.update(db.table, request.args(0))
delete_confirmation = T('Are you sure you want to delete this record?')
delBtn = A('Delete', _href=URL('delete_record',
args=['table', request.args(0)]),
_message=delete_confirmation,
_class='btn btn-small btn-danger',
_id='delBtn'
)
form.element('input', _type='submit', replace=lambda me: CAT(me, delBtn
))
return dict(form=form)
def delete_record():
tablename = request.args(0)
rec_id = request.args(1)
crud.delete(db[tablename], rec_id,
next=URL('select_table'), message=T('Deleted'
))
# view: 'update_record.html'
{{extend 'layout.html'}}
{{=form}}
<script type="text/javascript">
$(document).ready(function() {
$('#delBtn').click(function(e) {
e.preventDefault();
btn = $(this);
thisHref = btn.attr('href');
msg = btn.attr('message');
if(confirm(msg)){
window.location = thisHref;
}
});
})
</script>
Il giorno martedì 13 novembre 2012 21:26:08 UTC+1, Richard ha scritto:
>
> Hello,
>
> I would like to replace the way web2py allow the deletion of a record.
> Instead of the check to delete then confirm then submit... I would add a
> delete buttton on which is attached a confirmation message onclick then
> when the confirmation is confirmed the record is deleted.
>
> Actually I had this :
>
> form = crud.update(db.table, record)
> form.add_button(T('Delete'), '#', _class='btn-small
> btn-danger')
> delete_confirmation = T('Are you sure you want to delete this
> record?')
> try:
> form.element('input[value='+T('Delete')+']')['_onclick'] =
> "return confirm ('%s')" % delete_confirmation
> except:
> pass
>
> What I miss is how to actually set form.deleted=true as said in the book (
> http://web2py.com/books/default/chapter/29/07#SQLFORM-and-insert/update/delete
> )...
>
> I think I need a bit of JS, that detect the confirmation and will submit
> the form.
>
> Am I on the right track?
>
> Richard
>
>
>
--