Adding a tumbler switch to a form
An automatically generated material or service item form includes the MaterialServiceType field. Its values Material and Service are stored in the MaterialServiceTypes enumeration. The default field view is a text box where values are selected from a drop-down list.
If the number of enumeration items is small (2-3 items), you can display the field as a switch. A switch can have one of the following types: a set of radio buttons or a tumbler. The second option better suits modern application interfaces.
In Designer mode
Let us implement a switch.
- Create a custom form for the MaterialsAndServices catalog item.
- In the form controls tree, double-click the MaterialServiceType field.
- In the property palette, in the Type field, select Radio buttons.
- In the RadioButtonType field, select Tumbler.
- In the ChoiceList field, provide a list that consists of MaterialServiceTypes enumeration values (fig. 28.36).
Fig. 28.36. Switch field property palette
Let us also make another change. The Parent field stores the group where a catalog item belongs. And to move an item to the root of the hierarchy, a user should clear this field.
However, the clear button is disabled by default. There are other ways to clear the field, such as using the mouse or pressing Delete, but some users really need this button. Let us enable it. - In the Parent field property palette, in the ClearButton field, select Yes (fig. 28.37).
Fig. 28.37. Text box property palette
Note that text boxes have other properties that define button visibility: OpenButton, CreateButton, and more. The platform defines their visibility automatically but you can explicitly enable or disable them.
After the changes the form preview should look as shown in fig. 28.38.
Fig. 28.38. Catalog item form preview in the form editor
In 1C:Enterprise mode
Let us test the changes.
- Start 1C:Enterprise in the debug mode and open any item of the Materials and services catalog.
You can see that a tumbler switch is used for selecting between material and service. The selected value is displayed in green. And the Material or service group field has the Clear button (fig. 28.39).
Fig. 28.39. MaterialsAndServices catalog item form in 1C:Enterprise mode