Skip to Content
Menu
This question has been flagged
2 Replies
2981 Views

Hello ;


Dumb question maybe but...


I'm looking for the way to "send"/"put in place" default values inside each fields of my form (in the website part).

I have tried this way ( and it's ok ✔), if i prepare each default value in specifics variables and then place each field name with the good variable : 


  return request.render("module_name.id_of_the_form", 

       {            

         'first_name': user_connected_name,

         'email': mail_user_connected

       })


With this way, each field in my form have the good default value needed ( one variable by field).


⚠ But I wish to know why this one bellow doesn't works, when i use a variable as a dictionary  :


 default_values = {}        

default_values['first_name'] = request.env.user.partner_id.name        

default_values['email'] = request.env.user.partner_id.email        

 
        return request.render( "module_name.id_of_the_form ",  {default_values : 'default_values'])



The default_values dictionary contain all the informations needed to be put in place in the form, but the form didn't take thoses informations.


Thanks for your help :)

Avatar
Discard
Best Answer

You can do it using dictionary as below:

default_values = {}
default_values['first_name'] = request.env.user.partner_id.name
default_values['email'] = request.env.user.partner_id.email
return request.render( "module_name.id_of_the_form ",default_values)

or 

default_values = {'first_name':request.env.user.partner_id.name,
'email': request.env.user.partner_id.email }
return request.render( "module_name.id_of_the_form ",default_values)


Avatar
Discard
Author Best Answer

Hello Waleed ; 

Thanks  a lot for your response.

✔ The second one is the good for me :-)


Create the dictionnary with the rights values inside at once.

default_values = {'first_name':request.env.user.partner_id.name,
'email': request.env.user.partner_id.email }
return request.render( "module_name.id_of_the_form ",default_values)


Thanks :-)


Avatar
Discard
Related Posts Replies Views Activity
1
Nov 20
5337
0
Feb 21
2523
3
Apr 24
8405
3
Mar 24
3878
1
Jan 21
2218