跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. 关于新建对象时,客户端通过js函数为字段赋值的问题

关于新建对象时,客户端通过js函数为字段赋值的问题

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
4 帖子 2 发布者 4.2k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • X 离线
    X 离线
    xichun
    写于 最后由 编辑
    #1

    目的:新建对象时,在客户端通过调用js函数为对象字段赋值
    问题:赋值成功,保存时报"The following fields are invalid"错误


    部分视图代码:

    <br />&nbsp; &nbsp; &nbsp; &lt;group colspan=&quot;4&quot; col=&quot;6&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;group colspan=&quot;3&quot; col=&quot;3&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;field name=&quot;code&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/group&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;group colspan=&quot;3&quot; col=&quot;3&quot; attrs=&quot;{&#039;invisible&#039;: [(&#039;state&#039;,&#039;!=&#039;, &#039;draft&#039;)]}&quot;&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;html&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;embed id=&quot;simple&quot; type=&quot;application/nphid&quot; objname=&quot;simples&quot; hidden=&quot;true&quot; height=&quot;0&quot; width=&quot;0&quot; /&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;input type=&quot;button&quot; value=&quot;获得设备代码&quot; onclick=&quot;device_setparameters(98,this)&quot; class=&quot;oe_button oe_form_button_save&quot;/&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;html&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;/group&gt;<br />&nbsp; &nbsp; &nbsp; &lt;/group&gt;<br /><br />
    




    js代码如下:

    <br />function device_setparameters() {<br />&nbsp; &nbsp; var ophid = document.getElementById(&#039;simple&#039;);<br />&nbsp; &nbsp; var cmd = arguments[0];<br />&nbsp; &nbsp; var btn = $(arguments[1]);<br />&nbsp; &nbsp; var result;<br />&nbsp; &nbsp; if (cmd == 98) {<br />&nbsp; &nbsp; &nbsp; &nbsp; result = ophid.test(cmd);//调用插件的方法<br />&nbsp; &nbsp; &nbsp; &nbsp; if (result == &quot;&quot;) {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(&quot;没有设备连接到主机!&quot;);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(btn.parents(&#039;.oe_frame&#039;)[0]).parent().prev(&#039;td&#039;).find(&#039;:input&#039;).val(&#039;&#039;);<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; else<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(btn.parents(&#039;.oe_frame&#039;)[0]).parent().prev(&#039;td&#039;).find(&#039;input&#039;)[0].value=result;<br />&nbsp; &nbsp; }<br />}<br />
    



    当我点击"[b]获得设备代码[/b]"这个button时通过js函数"[b]device_setparameters[/b]"为[b]<field name="code"/>/b赋值,赋值成功,但在保存时提示"The following fields are invalid"


    [b]求解答[/b]


    [quote][/quote]

    1 条回复 最后回复
    0
    • X 离线
      X 离线
      xichun
      写于 最后由 编辑
      #2

      还是我自已来回答一下:

      添加js代码:$(btn.parents('.oe_frame')[0]).parent().prev('td').find('input').change();

      1 条回复 最后回复
      0
      • mrshellyM 离线
        mrshellyM 离线
        mrshelly
        写于 最后由 编辑
        #3

        嗯. 置了值以后, 再调用DOM对象的 change 事件, 让OE把余下的事儿干完...

        建议给贴子加上 tag, 以便检索...

        1 条回复 最后回复
        0

        • 登录

        • 没有帐号? 注册

        • 登录或注册以进行搜索。
        • 第一个帖子
          最后一个帖子
        0
        • 版块
        • 标签
        • 热门
        • 用户
        • 群组