Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
4192 มุมมอง

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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)


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

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


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Require checkbox to be selected แก้ไขแล้ว
1
พ.ย. 20
6505
0
ก.พ. 21
3581
2
พ.ค. 25
9707
3
มี.ค. 24
5333
Website form field conditions แก้ไขแล้ว
1
ม.ค. 21
3388