I am working on making a plugin where you have a list of fields i.e. 
telephone no and types and a insert form. That works very well.

Now, I want to add a facility that replaces the insert form with an update 
form once you click on one of the list items (telephone no).

I am sending the correct data to the controller, that is already tested via 
alerts.... I have also tested the "plumming" via a normal jQuery post 
statement and it returns the HTML of the update form to the view.

How do I get the ajax call to return the "update form" correctly and 
replace it with the original "insert form"?

Code looks like this:

*CONTROLLER*

def edit():
    if request.env.request_method == 'POST' and auth.user:
        entity = request.vars.entity
        entity_id = request.vars.entity_id
        id = request.vars.id
        form=SQLFORM(db.plugin_telephone, id).process()

        return form

*VIEW*

<script type="text/javascript">
    $(function() {
        $('.delete').bind('click', delete_record);
        $('.list').bind('click', edit_record);
    });

    function delete_record(evt) {
        var id = $(this).attr('data-id');
        $.post('{{=URL('delete')}}', {'id':id});
    }

    function edit_record(evt) {
        var entity = $(this).attr('data-entity');
        var entity_id = $(this).attr('data-entity-id');
        var id = $(this).attr('data-id');
        ajax('{{=URL('edit')}}', {'entity': entity, 'entity_id': entity_id, 
'id':id}, form);
    }
</script>

loop to create list and respective HTML to include needed data in list - 
that all works fine

{{=form}}

-- 
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