1C:Enterprise 8.3. Practical Developer’s Guide. Lesson 27 (2:10). Form development techniques. Choice form for a field with a reference attribute

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.

  1. 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.
  2. Click Add (fig. 27.26).

    Lesson 27 (2:10). Form development techniques / Choice form for a field with a reference attribute / In Designer mode
    Fig. 27.26. Creating an Employees catalog form
  3. In the form wizard that is opened, select Generic form and enter ChoiceForm for its name (fig. 27.27).

    Lesson 27 (2:10). Form development techniques / Choice form for a field with a reference attribute / In Designer mode
    Fig. 27.27. Creating a generic form for the Employees catalog
  4. 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.
  5. 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).

    Lesson 27 (2:10). Form development techniques / Choice form for a field with a reference attribute / In Designer mode
    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.
  6. Drag the List attribute to the form controls window.
  7. 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.
  8. 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.
  9. Right-click the root Form item, open its property palette, and then, in the CommandBarLocation field, select None (fig. 27.29).

    Lesson 27 (2:10). Form development techniques / Choice form for a field with a reference attribute / In Designer mode
    Fig. 27.29. Specifying form properties

    Next, let us enable selecting values from the table that contains the list of employees.
  10. In the List table property palette, select the ChoiceMode check box (fig. 27.30).

    Lesson 27 (2:10). Form development techniques / Choice form for a field with a reference attribute / In Designer mode
    Fig. 27.30. Table properties

    Finally, let us change the form title.
  11. In the form property palette, in the Title field, enter Select employees.
  12. Clear the AutoTitle check box.

    This prohibits displaying the extended presentation of the Employees catalog as the form title (fig. 27.31).

    Lesson 27 (2:10). Form development techniques / Choice form for a field with a reference attribute / In Designer mode
    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.
  13. Open the configuration object editor for the Services document.
  14. 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.
  15. Select ChoiceForm (fig. 27.32).

    Lesson 27 (2:10). Form development techniques / Choice form for a field with a reference attribute / In Designer mode
    Fig. 27.32. Specifying a choice form for a reference attribute

In 1C:Enterprise mode

Let us test the new form.

  1. Start 1C:Enterprise in the debug mode.
  2. Open any of the Services documents.
  3. In the Technician field, click the Select from list Lesson 27 (2:10). Form development techniques / Choice form for a field with a reference attribute / In 1C:Enterprise mode 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).

    Lesson 27 (2:10). Form development techniques / Choice form for a field with a reference attribute / In 1C:Enterprise mode
    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

1C:Enterprise Developer's Community