Odoo中文社区可以通过以下两个域名访问:shine-it.net , odoo.net.cn

由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

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



  • 目的:新建对象时,在客户端通过调用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]



  • 还是我自已来回答一下:

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



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

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


Log in to reply