【问题标题】:How to make a field readonly if it is not null using css in openerp 7?如果在 openerp 7 中使用 css 不为空,如何将字段设为只读?
【发布时间】:2017-07-27 06:35:08
【问题描述】:

如果所有字段在 openerp 7 中有值而不使用 attrs 命令,我想将其设为只读。如果我使用 attrs,我需要在所有字段中进行定义。

.openerp .oe_form .oe_form_field_char input,
.openerp .oe_form .oe_form_field_url input,
.openerp .oe_form .oe_form_field_email input,
.openerp .oe_form .oe_form_field_text textarea,
.openerp .oe_form .oe_form_field_selection select {
  width: 10%;
}

这是定义所有字段宽度的css代码。我想使用这种方法来实现我的要求。

【问题讨论】:

  • 您不能使用 css 创建字段 readonly。你也许可以像stackoverflow.com/a/16811266/1514875 一样hack
  • 为所有字段定义attrs 的问题在哪里?如果你使用groups,你也可以在其中定义attrs

标签: css xml openerp


【解决方案1】:

纯css没办法,必须借助jquery:

$(document).ready(function(){
    $('input[type=text],textarea').each(function(){
       if($(this).val().length > 0)
        $(this).attr('readonly','readonly');
    })

    $('select').each(function(){
       if($(this).val().length > 0)
        $(this).attr('disabled','disabled');
    })
})

$(document).ready(function(){
    $('input[type=text],textarea').each(function(){
       if($(this).val().length > 0)
        $(this).attr('readonly','readonly');
    })

    $('select').each(function(){
       if($(this).val().length > 0)
        $(this).attr('disabled','disabled');
    })
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Text: <input type="text">
Textarea:<textarea></textarea>
Select:
<select>
   <option></option>
    <option>Ehsan</option>
    <option>Taghdisi</option>
</select>
<br><br><br>
Text: <input type="text" value="Some Text...">
Textarea:<textarea>Some Text...</textarea>
Select:
<select>
    <option>Some Text...</option>
    <option>Taghdisi</option>
</select>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多