Form and Read only fields

Hi all,

I tried to lock some fields in a form using “field.setReadOnly(true)” … But nothing happens and the field is still editable …

You can try with the VAADIN Address Book Example :

  • Open file “com.vaadin.demo.tutorial.addressbook.ui.PersonForm”
  • Go to row 105
  • Add “field.setReadOnly(true);”

Then, run the application and try to add or modify a person … The “email” field is not read only !!!

Did i miss anything or is it a bug ?

Thank you.

Hi James,

The addressbook demo uses form.setReadOnly()-method (line 165 “super.setReadOnly(readOnly);”) when the edit button of the person form is clicked. Calling the setReadOnly() method for the form is equivalent for calling setReadOnly() method for the each field of the form. Therefore, even if you set a field to readOnly(true) the later call of form.setReadOnly(false) enables all the form fields for editing.

Best regards

Thanks for the answer … i understand now …

but now i have 2 improvment ideas :

1 - Add readonly field list

Add new method to form called “setReadOnlyItemProperties” who keep and apply automaticaly ReadOnly after form mode change.

2 - Focus and Readonly

It is strange that readonly field is focusable … So adding property to low level object (like “Component” class) called “focusable”.

And then, it can control focusable elements in UI.

Don’t you think ?

Thanks for the ideas! These ideas might be considered when the Vaadin R&D team will ponder how to improve and facilitate the usage of the Form component. It is well known that the Form component needs some improvements since it is not so self-evident to use it.

Best regards,