# Hide label in form view when the field is invisible

**URL:** <https://discuss.tryton.org/t/hide-label-in-form-view-when-the-field-is-invisible/2522>\
**Category:** Ideas\
**Created:** [April 1, 2020, 7:08am UTC](https://discuss.tryton.org/t/hide-label-in-form-view-when-the-field-is-invisible/2522 "2020-04-01T07:08:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![resteve](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/resteve/32/823_2.png) [@resteve](https://discuss.tryton.org/u/resteve)\
**Post date:** [April 1, 2020, 7:08am UTC](https://discuss.tryton.org/t/hide-label-in-form-view-when-the-field-is-invisible/2522/1 "2020-04-01T07:08:52Z")

</div>

Current, when we like to hide a field, we do:

```auto
def _setup__(cls):
    super(cls). __setup__ ()
    cls.field_name.states['invisible'] = True

```

Also we need a extra task: hide the label in XML form view:

```auto
    <xpath expr="/form/notebook/page[@id='xxxxx']/label[@name='field_name']" position="replace"></xpath>

```

IMHO when hide a field, also we need to hide the label.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [April 1, 2020, 7:54am UTC](https://discuss.tryton.org/t/hide-label-in-form-view-when-the-field-is-invisible/2522/2 "2020-04-01T07:54:20Z")

</div>

Could you elaborate why you need to hide a field in a view?  
Why you dont replace the field directly with the xpath?

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [April 1, 2020, 9:24am UTC](https://discuss.tryton.org/t/hide-label-in-form-view-when-the-field-is-invisible/2522/3 "2020-04-01T09:24:13Z")

</div>

The label inherit the `states` from its field but only if it does not have already a states defined. This behavior is used for almost all fields that we made invisible.

---

<div class="post-metadata">

**Author:** ![resteve](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/resteve/32/823_2.png) [@resteve](https://discuss.tryton.org/u/resteve)\
**Post date:** [April 1, 2020, 11:54am UTC](https://discuss.tryton.org/t/hide-label-in-form-view-when-the-field-is-invisible/2522/4 "2020-04-01T11:54:46Z")

</div>

> [@pokoli](#):
>
> Why you dont replace the field directly with the xpath?

… because you need replace all views. All tree views, all form views, …

Example:  
Module “A” add “b” field.  
Custom module, hide “b” field because don’t need but need other fields or features defined in module “A”.
