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.

2
  • You can not make a field readonly with css. You might be able to hack it like stackoverflow.com/a/16811266/1514875 Commented Jul 27, 2017 at 6:37
  • Where is the problem defining attrs for all fields? If you use groups you can define attrs in them, too. Commented Jul 27, 2017 at 7:19

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.