Skip to Content
Menu
This question has been flagged

Hi 


I have a form which might failed, so I put a field "<span id="o_website_form_result"></span>" in the form expecting to receive error message, but I don't know how to return the message from the controller. Is there anyone know how?


Thanks!


J

Avatar
Discard
Author Best Answer

After spending hours to trace into the JQuery source code, eventually I figured it out. I must return something like:

{'error_fields': {

    'first_name': 'Invalid first name',

    'last_name': 'Invalid last name'

}}

And not enough, I also have to put some specific CSS markup to the place where I want the error message be shown. I'm not a frontend developer and not familiar with JQuery, so it does make me headache, but fortunately I walked it out. Now everything looks perfect.

By the way, maybe a good recommendation to Odoo is to provide more document for UI development, especially for out-of-box website script and CSS markup would be very appreciated.

Avatar
Discard
Best Answer

Hi,

Look into default odoo core module source code you can get idea.

Based on your requirement default core module code.

Xml template
https://github.com/odoo/odoo/blob/13.0/addons/mass_mailing_sms/views/mass_mailing_sms_templates_portal.xml

<div t-if="unsubscribe_error" class="alert alert-danger text-center" role="alert">
<p>There was an error when trying to unsubscribe <strong t-esc="sms_number"/></p>
<p t-esc="unsubscribe_error"/>
</div>

https://github.com/odoo/odoo/blob/13.0/addons/mass_mailing_sms/controllers/main.py
Controllers.py
@http.route(['/sms/<int:mailing_id>/unsubscribe/<string:trace_code>'], type='http', website=True, auth='public')
def blacklist_number(self, mailing_id, trace_code, **post):
if tocheck_number and trace.sms_number == tocheck_number:
    # code.....
elif tocheck_number and trace.sms_number != tocheck_number:
unsubscribe_error = _('Number %s not found' % tocheck_number)
else:
unsubscribe_error = sanitize_res['msg']

return request.render('mass_mailing_sms.blacklist_number', {
'mailing_id': mailing_id,
'trace_code': trace_code,
'sms_number': sms_number,
'lists_optin': lists_optin,
'lists_optout': lists_optout,
'unsubscribe_error': unsubscribe_error,
})


Avatar
Discard
Author

No, it is not the way, Obviously it requires JSON format return, HTML not gonna work.

Related Posts Replies Views Activity
1
Mar 15
3549
0
Dec 24
154
1
Feb 24
1411
2
Nov 24
13175
2
Dec 21
22893