[web2py] Re: pop-up verification

2012-03-29 Thread Derek
Take a look at this: http://web2py.com/books/default/chapter/29/7#FORM

Specifically this example:

db.define_table('numbers',
Field('a', 'integer'),
Field('b', 'integer'),
Field('c', 'integer', readable=False, writable=False))

def my_form_processing(form):
c = form.vars.a * form.vars.b
if c < 0:
   form.errors.b = 'a*b cannot be negative'
else:
   form.vars.c = c

def insert_numbers():
   form = SQLFORM(db.numbers)
   if form.process(onvalidation=my_form_processing).accepted:
   session.flash = 'record inserted'
   redirect(URL())
   return dict(form=form)

What you want to do is write your own validator, so that it will check if 
the data is already in the database, and if so, modify the form such that 
there is an extra checkbox 'i am sure that i know that this is already 
there'.
Perhaps that will help?

On Tuesday, March 27, 2012 1:14:02 PM UTC-7, Larry Wapnitsky wrote:
>
> Last question of the day, I promise...
>
> So, I have data that exists in my database.  If a user enters a value 
> that already exists, I want to prompt them with an "are you sure?" type 
> question before the function that adds/updates the data continues.
>
> How do I interrupt my current function to do so without leaving the page 
> and losing data?
>
> Thanks,
> Larry
>
>

[web2py] Re: pop-up verification

2012-03-27 Thread pbreit
I have a Jquery dialog on one of my pages that I think does something 
similar. So when the user clicks "list", the dialog pops up and then when 
they press "Ok" it sets the window.location to a new URL. But I'm guessin 
you probably need to do a POST which I'm not quite sure how that would work.


list

$(function() {
$("#dialog-form").dialog({
autoOpen: false,
show: 'fade',
hide: 'fade',
modal: true,
resizable: false,
width: 200,
minHeight: 190,
buttons: {
"Close": function() { $(this).dialog("close"); },
"Ok": function() { window.location = "{{=URL('ebay', 'api', 
args=['list', item.id])}}?ebay_category=" + 
document.getElementById("ebay_category").value; }
}
});

$('#opener').click(function(e) {
e.preventDefault();
$dialog.dialog('open');
});
});