You've already forked v8-code-style
mirror of
https://github.com/1C-Company/v8-code-style.git
synced 2025-12-05 10:12:17 +02:00
58 lines
1.6 KiB
Markdown
58 lines
1.6 KiB
Markdown
|
|
# Program invocation of form event handler
|
||
|
|
|
||
|
|
Assign a handler for each event.
|
||
|
|
If different actions are required in case of events in different form items:
|
||
|
|
|
||
|
|
- Create a separate procedure or a function that executes the required action.
|
||
|
|
- Сreate a separate handler with a default name for each form item.
|
||
|
|
- Call the required procedure or function from each handler.
|
||
|
|
|
||
|
|
## Noncompliant Code Example
|
||
|
|
|
||
|
|
```bsl
|
||
|
|
&AtClient
|
||
|
|
Procedure ByPerformerOnChange(Item)
|
||
|
|
FilterParameters = New Map();
|
||
|
|
FilterParameters.Insert("ByAuthor", ByAuthor);
|
||
|
|
FilterParameters.Insert("ByPerformer", ByPerformer);
|
||
|
|
SetListFilter(List, FilterParameters);
|
||
|
|
EndProcedure
|
||
|
|
|
||
|
|
&AtClient
|
||
|
|
Procedure ByAuthorOnChange(Item)
|
||
|
|
ByPerformerOnChange(Undefined);
|
||
|
|
EndProcedure
|
||
|
|
```
|
||
|
|
|
||
|
|
## Compliant Solution
|
||
|
|
|
||
|
|
```bsl
|
||
|
|
&AtClient
|
||
|
|
Procedure ByPerformerOnChange(Item)
|
||
|
|
SetFilter();
|
||
|
|
EndProcedure
|
||
|
|
|
||
|
|
&AtClient
|
||
|
|
Procedure ByAuthorOnChange(Item)
|
||
|
|
SetFilter();
|
||
|
|
EndProcedure
|
||
|
|
|
||
|
|
&AtServer
|
||
|
|
Procedure SetFilter()
|
||
|
|
FilterParameters = New Map();
|
||
|
|
FilterParameters.Insert("ByAuthor", ByAuthor);
|
||
|
|
FilterParameters.Insert("ByPerformer", ByPerformer);
|
||
|
|
SetListFilter(List, FilterParameters);
|
||
|
|
EndProcedure
|
||
|
|
```
|
||
|
|
|
||
|
|
These requirements are provided as logically event handlers are not intended for use in the module code but
|
||
|
|
are called directly by the platform. If you mix these two scenarios in a single procedure,
|
||
|
|
its logic gets complicated and decreases its stability.
|
||
|
|
Instead of one predefined call scenario by an event from the platform,
|
||
|
|
the procedure code needs to consider other "direct" calls from the code.
|
||
|
|
|
||
|
|
## See
|
||
|
|
|
||
|
|
- [Module structure](https://support.1ci.com/hc/en-us/articles/360011002360-Module-structure)
|