0

I want to make all fields readonly if it has values in openerp 7 without using attrs command. If i use attrs i need to define in all fields.

.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%;
}

this is the css code to define width of all fields.I want to use this type of method to acheive my requirements.

Naglis
  • 2,583
  • 1
  • 19
  • 24
Dinesh
  • 35
  • 1
  • 7
  • You can not make a field `readonly` with css. You might be able to *hack* it like https://stackoverflow.com/a/16811266/1514875 – TryingToImprove Jul 27 '17 at 06:37
  • Where is the problem defining `attrs` for all fields? If you use `groups` you can define `attrs` in them, too. – CZoellner Jul 27 '17 at 07:19

1 Answers1

0

There is no way with pure css,you must help of 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>
Ehsan
  • 12,655
  • 3
  • 25
  • 44