I'm making a form inside a module that is meant to show up in a bootstrap 
modal in one of my views. 

    new_form = SQLFORM.factory(
            Field('title', type="string", required=True),
            Field('author', type="string"),
            Field('co-author', type="string"),
            Field('institution', type="string"),
            Field('date',  type='string'),
            labels = {
                'title' : 'Title',
                'author': 'Author(s)',
                'coauthor': 'Coauthor(s)',
                'institution': 'Institution',
                'date': 'Date'
            },
            submit_button=T('Create')
    )

Is there a way that I can check if at least one of the 'author', 'coauthor' 
and 'institution' fields has been filled before processing the form? So 
far, i've tried using an onvalidation function that effectively checks this:

def authors_check(form):
    if not(form.vars.author or form.vars.coauthor or form.vars.institution):
        form.errors.author = 'Debe haber al menos un autor, o un coautor, o 
un autor institucional'

def process_form(form):
    if form.process(onvalidation=authors_check).accepted:
    .......

The problem is that with this approach, the validation occurs after the 
user has clicked the submit button and the modal has closed, the user would 
have to navigate to open the modal all over again. Is there a way I can 
check this before the user has hit the submit button, or at least to make 
the modal not close if the form detects an error? 

Here is the modal i have in my view:

<!-- Example modal-->
<div class="container">
  <div class="modal fade" id="modalExample" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" 
data-dismiss="modal">&times;</button>
          <center> <h4 class="modal-title">Add book</h4> </center>
        </div>
        <div class="modal-body">
          <center>
            <p>Please fill the following form:</p>
          </center>
            <br>
            {{=new_form}}
        </div>
      </div>
    </div>
  </div>
</div>

Thanks in advance for any help. 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to