Hello Massimo,

This proposal tries to address the last point mentioned in [1], quoted
below.

    "...... when deleting a record, form variables should be cleared
which is not the case here. In my openion this’s not a good idea in
fact, and needs to be fixed because it’s really tempting to see the
variables still in the form and makes one clicks the ['submit'] button
again to see what would happen and it returns ‘object not found’ error
message."


An easy idea, which was also suggested in [1], is to use redirect(...)
after successful record deletion. But that is not one-size-fits-all
because developers need to provide target URL in every case.

Then I planned to somehow compulsively replace the form object with a
string such as "delete ok", but it would cause backward compatibility
problem when a customized view file expecting a real form object.

Finally I got the idea. SQLFORM.accepts() can disable all form fields
after deletion, to indicating a successful deletion and also avoid
further operation! crud also benefits from this improvement. Try the
patch.

>From line 920 of sqlhtml.py:

        if record_delete:
            ......
            self.errors.clear()
 
self.components.append(SCRIPT("""jQuery(document).ready(function(){
                jQuery('input, select').attr('disabled',
'disabled'); })""",
                _type="text/javascript")) # to emphasize the record is
deleted and avoid further operation
            return True



[1] 
http://web2py.wordpress.com/2010/05/02/record-deletion-and-keepvalues-in-forms/

Sincerely,
             Iceberg, 2010-May-28, 03:07(AM), Fri

Reply via email to