Choice form for a field with a reference attribute
Users often enter data in fields that store reference attributes (attributes that reference some configuration objects).
For example, in the Services document they fill the following reference fields: Customer (type: CatalogRef.Customers), Technician (type: CatalogRef.Employees), and so on.
Clicking the selection button in a reference field opens the default choice form of the respective configuration object (Customers catalog, Employees catalog, and more).
You might need to use a custom choice form for a reference attribute. To do so, in the Choice form property of the attribute, specify the custom form. That custom form will be opened every time this attribute is selected in any form.
In Designer mode
Let us use the Services document as an example. Suppose that you do not want to use the default choice form of the Employees catalog for selecting a value in the Technician field and you want to use a custom form instead.
First you have to create this form.
- Open the editor of the Employees catalog configuration object and click the Forms tab.
This object has no forms at all. This means that all the catalog forms used in 1C:Enterprise mode (including the choice form) are generated automatically.
- Click Add (fig. 27.26).
Fig. 27.26. Creating an Employees catalog form
- In the form wizard that is opened, select Generic form and enter ChoiceForm for its name (fig. 27.27).
Fig. 27.27. Creating a generic form for the Employees catalog
- Click Finish.
The form has no controls or data because it is a generic form and you can populate it with data and controls as you want.
- On the Attributes tab, create a main form attribute named List with DynamicList type, and set its Main table property to Catalog.Employees (fig. 27.28).
Fig. 27.28. Creating a main form attribute
Attention! It is important that you select the Main attribute check box. If you skip this step, the form is unable to determine its data source.
- Drag the List attribute to the form controls window.
- When asked "Add columns to the table "List"?", click Yes.
This adds the List table, which contains a list of employees, to the form.
Now let us slightly modify the form appearance.
- In the form controls pane, expand the List table and delete the Code field.
Since the table has its own command bar, let us hide the form command bar.
- Right-click the root Form item, open its property palette, and then, in the CommandBarLocation field, select None (fig. 27.29).
Fig. 27.29. Specifying form properties
Next, let us enable selecting values from the table that contains the list of employees.
- In the List table property palette, select the ChoiceMode check box (fig. 27.30).
Fig. 27.30. Table properties
Finally, let us change the form title.
- In the form property palette, in the Title field, enter Select employees.
- Clear the AutoTitle check box.
This prohibits displaying the extended presentation of the Employees catalog as the form title (fig. 27.31).
Fig. 27.31. Specifying form properties
So you have created a form that is very similar to the choice form. You have removed the Code field from the list and modified the form title to make it different from the choice form.
Obviously in reality generic form functionality should be different from that of the choice form because otherwise making it the choice form does not make sense. But this is beyond your current task. The only thing we want to demonstrate is how a generic form is used as a choice form.
- Open the configuration object editor for the Services document.
- Open the property palette of the Technician attribute and click the selection button in the Selection Form field.
This opens a list of custom forms created in the configuration for the object referenced by this attribute. The Tecnhician attribute references the Employees catalog, which has a single custom form: ChoiceForm.
- Select ChoiceForm (fig. 27.32).
Fig. 27.32. Specifying a choice form for a reference attribute
In 1C:Enterprise mode
Let us test the new form.
- Start 1C:Enterprise in the debug mode.
- Open any of the Services documents.
- In the Technician field, click the Select from list button and then, in the drop-down list, click Show all.
This opens the custom form that you created, with Select employees as a title (fig. 27.33).
Fig. 27.33. Employee choice form
Since you have defined the Selection Form property at the Technician attribute level instead of the form level, any form of the Services document that includes the attribute opens this custom form to select a technician.
If you clear the Selection Form property of the Technician attribute in the Services document, an attempt to select a value in the Technician field in 1C:Enterprise mode opens the automatically generated default form of the Employees catalog.