there are three problems:
1) you edit edit_governorate via ajax but the page still submits to
governorate so it is processed by the wrong accept
2) you do not have a machanim (formname) to distinguish which form
needs processing
3) you do not have a mechanism to show errors if edit_governorate does
not pass validation
Using web2py_ajax.html functions would have solved this problem for
you without need to edit controllers. Since you are not using it you
can try this:
def governorate():
form = crud.update(db.governorate,request.args(0)) # will process
both create and update
query = auth.accessible_query('CAN_VIEW',
db.governorate,auth.user.id)
governorates=db(query).select(orderby=db.governorate.name)
return dict(governorates=governorates, form=form)
def edit_governorate():
if not auth.has_permission('CAN_VIEW', db.governorate,
0,auth.user.id):
raise HTTP(403)
form = crud.update(db.governorate ,request.args(0))
form['_action']=URL(r=request,f='governorate',args=request.args)
return dict(form=form)
the view looks like :
governorate.html
---------------------
<script type="text/javascript">
function func(id) {
var url = "{{=URL(request.application,
'admin','edit_governorate')}}/"+id;
ajax(url, [], 'governorate_form');
};
</script>
<div id="governorate_form">
<h3>{{=T("New Governorate")}}</h3>
{{=make_clickable("New Governorate","admin","governorate")}}
{{=form}}
</div>
<br/>
<br/>
<table>
<thead>
<tr>
<th>
{{=T("Governorate Name")}}
</th>
</tr>
</thead>
<tbody>
{{for governorate in governorates:}}
<tr>
<td>
<a href="# " id='update_governorate'
onclick="func('{{=governorate.id}}');">{{=governorate.name}}</a>
</td>
</tr>
{{pass}}
</tbody>
</table>
in the edit_governorate.html
---------------------------------
{{=A(T("Add New Governorate"), _href=URL(request.application,
'admin','governorate'))}}
{{=form}}
On Feb 8, 1:24 am, "hamdy.a.farag" <[email protected]> wrote:
> ok
>
> 1st of all, I don't use "web2py_ajax_page" functions
>
> and the particular code looks like :
>
> def governorate():
> form = crud.create(db.governorate)
> query = auth.accessible_query('CAN_VIEW', db.governorate,
> auth.user.id)
> governorates=db(query).select(orderby=db.governorate.name)
> return dict(governorates=governorates, form=form)
>
> def edit_governorate():
> if not auth.has_permission('CAN_VIEW', db.governorate, 0,
> auth.user.id):
> raise HTTP(403)
> form = SQLFORM(db.governorate ,request.vars.gov_id)
> #crud.update(db.governorate ,request.vars.gov_id)
> if form.accepts(request.vars, formname=None):pass
> return dict(form=form)
>
> the view looks like :
>
> governorate.html
> ---------------------
>
> <script type="text/javascript">
> function func(id) {
> var url = "{{=URL(request.application, 'admin',
> 'edit_governorate')}}"+ "?gov_id=" + id;
> ajax(url, [], 'governorate_form');
> };
> </script>
>
> <div id="governorate_form">
> <h3>{{=T("New Governorate")}}</h3>
>
> {{=make_clickable("New Governorate","admin","governorate")}}
> {{=form}}
> </div>
> <br/>
> <br/>
> <table>
> <thead>
> <tr>
> <th>
> {{=T("Governorate Name")}}
> </th>
> </tr>
> </thead>
> <tbody>
> {{for governorate in governorates:}}
> <tr>
> <td>
> <a href="# " id='update_governorate' onclick=
> "func('{{=governorate.id}}');">{{=governorate.name}}</a>
> </td>
> </tr>
> {{pass}}
> </tbody>
> </table>
>
> in the edit_governorate.html
> ---------------------------------
>
> {{=A(T("Add New Governorate"), _href=URL(request.application, 'admin',
> 'governorate'))}}
> {{=form}}
>
> Now is the symbtoms are as follows :
>
> I can add new governorate using an add form and record does appear
> immediately in my table below the form in the same page
> when clicking a table record which is a governorate, the update form
> does appear correctly in the same place that "the add new form"
> appears , and the "add new" does disappear
> The problem is thst I ca't update/delete the update form , when
> clicking submit button, the update form does disaapear and the other
> form [add new] does appear, but records are not updated
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.