I’m struggling with the use of the view_attributes. I want to remove a field from a form when a certain condition is met. Otherwise the field should be visible.
Basically I want to say “If order is empty, set the colspan of the location to -1. Else do nothing”. I have tried several versions, but none of them are working. On the client side I get a message like:
ValueError: invalid literal for int() with base 10: '{"__class__": "If", "c": {"__class__": "Bool", "v": {"__class__": "Eval", "v": "order", "d": -1}}, "t": -1, "e": 2}'
I don’t want to make the field just invisible because I want to remove the empty space as well.
You can not. colspan can not be dynamic, it is set only once when the view XML is parsed.
If you want to hide a field based on a statement, you should use the states['invisible'] of the field.
But states['invisible'] will only hide the field and does not give the space back right?
Would it be possible to display another field in that location? or will it be left empty?
Thanks, I read that one and came up with the idea to use the colspan in the view_attributes.
For even more completeness, I had to hide two fields which makes it one row in the grid. I did put that row just above the tabs. Using it this way and hiding the fields, removes the empty space. So no need to use view_attributes, this can be defined on the field itself.