Hi, it's been a long time and now I have this really odd issue, I have
a model like this:

models/db_01.py

db.define_table('dogs',
    Field('name'),
    Field('owner'),
    Field('age'),
    Field('adress'))

In my view generate a grid, which has a lot of dogs, and each one had a
modal to view details/edit, but as the table gets bigger page loading
gets slower since it has to generate all the modals, one solution I
came up with is creating only one modal and attach the view button to a
jquery event and load the form in the modal, so mi controller goes like
this:

controllers/app.py

# list of all the dogs
def index():
    list=db(db.dogs.id>0).select()

    return dict(list=list)

def dogDetails():

    id = request.args(0)

    if id:
        # if id provided returns an update form
         form=SQLFORM(db.dogs, id)

            if form.process().accepted:
                session.flash='it works!'
            elif form.errors:
                session.flash= 'not working'
    else:
        # if not id, creates a new record
            form=SQLFORM(db.dogs)
            if form.process(formname=None).accepted:
                    session.flash='it works!'
            elif form.errors:
                    session.flash= 'Something broken'

    return dict(form=form)

so, views look like this:

app/index.html

{{extend 'layout.html'}}

<div class="container">
  <div class="well">
    <h3>Complete list</h3>

    <a class="callForm btn btn-primary" href="#"><span class="glyphicon
    glyphicon-plus"></span> New dog</a>

    <table class="table table-hover">
      <thead>
        <tr>
          <th>Name</th>
          <th>Owner</th>
          <th>Age</th>
          <th>Edit</th>
        </tr>
      </thead>
      <tbody>
        {{for dog in list:}}
        <tr>
          <td>{{=dog.name}}</td>
          <td>{{=dog.owner}}</td>
          <td>{{=dog.age}}</td>
          <td><a class="btn btn-primary callForm" href="#"
          id="{{=dog.id}}"><span class="glyphicon
          glyphicon-pencil"></span></a></td> </tr> {{pass}}
      </tbody>
    </table>
  </div>
</div>

<!-- modal stuff -->
<div class="modal fade" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"
aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title"></h4>
      </div>
      <div class="modal-body">

    <!-- Here is where ajax content is loaded!!!! -->

      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

and app/dogDetails.load

{{=form}}

So, everything gets glued with some javascript and jquery code that
looks like this, nothing fancy but partially works:

$(document).ready(function(){
  $('.callForm').on('click', function(){
    // get the id of current element
    var id = $(this).attr('id');

    // if element gets a edit record, else shows an empty form for new
    record
    if (id != undefined){
      $('.modal-body').load('dogDetails.load/'+id, function(){
        $('.modal-title').text('Edit record');
      })
    }else{
      $('.modal-body').load('dogDetails.load', function(){
        $('.modal-title').text('New record');
      })
    }
    $('.modal').modal('toggle');

  })
})

so far it shows forms and everything, but it is not submitting either
new records or even updates, no error. Maybe I'm missing something
really obvious but can't find out what.

Thanks in advance for taking the time to read this long problem...

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to