【问题标题】:How to fix radio button default with two radio button different field如何使用两个单选按钮不同的字段修复单选按钮默认值
【发布时间】:2017-09-28 09:36:44
【问题描述】:

我在网站上有两个不同字段名称的单选按钮。第一个单选按钮 delivery_option(我自己制作),第二个单选按钮(carrier_id)。我想两个单选按钮之间的关系。如果我检查delivery_option 自动检查单选按钮carrier_id。如何解决?

    <template id="delivery_opt" inherit_id="website_sale.payment" customize_show="True" name="Delivery Option">

        <xpath expr="//div[@id='payment_method']" position="before">

            <div class="row" id="delivery_option">
              <div class="col-lg-5 col-sm-6">
              <h4>Choose your Delivery</h4>
                  <ul class="list-unstyled">
                      <li>
                          <label>
                              <input value="once" type="radio" name="delivery_options"
                                t-att-checked="order.delivery_options == 'once' and 'checked' or False"
                                />
                              <span>Every day</span>
                          </label>
                      </li>
                      <li>
                          <label>
                              <input value="twice"  type="radio" name="delivery_options"
                                t-att-checked="order.delivery_options == 'twice' and 'checked' or False"
                                  />
                              <span>Every two day</span>
                          </label>
                      </li>
                  </ul>
              </div>
          </div>

  </xpath>

</template>

<template id="delivery_method_def" name="Delivery Method Default" inherit_id="website_sale.payment">
    <xpath expr="//div[@id='payment_method']" position="before">
        <div t-if="deliveries" class="row" id="delivery_carrier">
            <div class="col-lg-5 col-sm-6">
            <h4>Choose your Delivery Method</h4>
                <ul class="list-unstyled">
                    <li t-foreach="deliveries" t-as="delivery">
                        <t t-if="delivery.available">
                            <label>
                                <input t-att-value="delivery.id" type="radio" name="delivery_type"
                                    t-att-checked="order.carrier_id and order.carrier_id.id == delivery.id and 'checked' or False"/>
                                <abbr t-att-title="delivery.website_description"><span t-field="delivery.name"/></abbr>
                                <span class="badge" t-field="delivery.price"
                                    t-options='{
                                        "widget": "monetary",
                                        "from_currency": delivery.product_id.company_id.currency_id,
                                        "display_currency": website_sale_order.currency_id
                                    }'/>
                                <div t-field="delivery.website_description" class="text-muted"/>
                            </label>
                        </t>
                    </li>
                </ul>
            </div>
        </div>
    </xpath>
</template>

【问题讨论】:

    标签: javascript python web


    【解决方案1】:

    试试下面的代码。当您更改您的 delivery_options 字段时使用 javaScript 事件函数,如果 delivery_options 值为 true,其他字段也将更改。并且还将 id 提供给 carrier_id。

      <input value="once" type="radio" name="delivery_options"  id="delivery" onchange="myFunction()"                            t-att-checked="order.delivery_options == 'once' and 'checked' or False"/>
           <script>
            function myFunction() {
                      if($("#delivery_option").checked === true){
                     $("#carrier_id").val() = "true"
               }
                  }
            </script>
    

    【讨论】:

    • 尊敬的 Salman 感谢您的回复,我使用 .py 和 .xml 。我尝试使用这个 order.write({'carrier_id': 1}) print 'order.carrier_id', order.carrier_id.id 但我只得到一个带有 ID 的值。我想改变很多价值。 carrier_id 字段类型 many2one
    • 你能和我分享你的代码吗?或请详细说明。
    • 我的代码 .xml 与上面相同,我的代码在 .py _inherit = 'sale.order' delivery_options = fields.Selection([ ('once', 'Every day'), ('twice' , '每两天')], string='交货选项')
    猜你喜欢
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    • 2012-04-13
    • 2019-08-19
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多