|
2 | 2 |
|
3 | 3 | <Badge type="tip" vertical="top" text="Elementor Pro" /> <Badge type="warning" vertical="top" text="Advanced" />
|
4 | 4 |
|
5 |
| -Some form fields are dependent on custom scripts for functionality and custom styles for look and feel. |
| 5 | +Some form fields are dependent on custom scripts for functionality, and custom styles for look and feel. Let's see how to set field dependencies. |
6 | 6 |
|
7 | 7 | ## Dependency Properties
|
8 | 8 |
|
9 |
| -Inside the field class we can enqueue any required JS and CSS dependencies the following way: |
| 9 | +Inside the field class we can require any JS or CSS dependencies the following way: |
10 | 10 |
|
11 | 11 | ```php
|
12 | 12 | class Elementor_Test_Field extends \ElementorPro\Modules\Forms\Fields\Field_Base {
|
13 | 13 |
|
14 |
| - public $depended_scripts = [ 'script-handle' ]; |
| 14 | + public function get_script_depends(): array { |
| 15 | + return [ 'script-handle' ]; |
| 16 | + } |
15 | 17 |
|
16 |
| - public $depended_styles = [ 'style-handle' ]; |
| 18 | + public function get_style_depends(): array { |
| 19 | + return [ 'style-handle' ]; |
| 20 | + } |
17 | 21 |
|
18 | 22 | }
|
19 | 23 | ```
|
20 | 24 |
|
21 |
| -* **Field Scripts** – The `$depended_scripts` property defines the JS files required to display the field. |
| 25 | +* **Field Scripts** – The `get_script_depends()` method defines the JS files required to display the field. |
22 | 26 |
|
23 |
| -* **Field Styles** – The `$depended_styles` property defines the CSS files required to display the field. |
| 27 | +* **Field Styles** – The `get_style_depends()` method defines the CSS files required to display the field. |
24 | 28 |
|
25 | 29 | ## Registering Scripts & Styles in WordPress
|
26 | 30 |
|
@@ -69,33 +73,29 @@ Then, each form field should set its dependencies as follows:
|
69 | 73 | ```php
|
70 | 74 | class Elementor_Test_Field extends \ElementorPro\Modules\Forms\Fields\Field_Base {
|
71 | 75 |
|
72 |
| - public $depended_scripts = [ 'field-script', 'external-library' ]; |
| 76 | + public function get_script_depends(): array { |
| 77 | + return [ 'field-script', 'external-library' ]; |
| 78 | + } |
73 | 79 |
|
74 |
| - public $depended_styles = [ 'field-style', 'external-framework' ]; |
| 80 | + public function get_style_depends(): array { |
| 81 | + return [ 'field-style', 'external-framework' ]; |
| 82 | + } |
75 | 83 |
|
76 | 84 | }
|
77 | 85 | ```
|
78 | 86 |
|
79 |
| -## Future Development |
80 |
| - |
81 |
| -Our roadmap includes a task to unify the way scripts and styles are registered across different components. |
| 87 | +## Backwards Compatibility |
82 | 88 |
|
83 |
| -We plan to deprecate the `$depended_scripts` and `$depended_styles` properties, replacing them with the `get_script_depends()` and `get_style_depends()` methods. The same way it's done in [widgets](./../widgets/widget-dependencies/). |
| 89 | +Until Elementor 3.29, dependency declaration done using `$depended_scripts` and `$depended_styles` properties: |
84 | 90 |
|
85 | 91 | ```php
|
86 | 92 | class Elementor_Test_Field extends \ElementorPro\Modules\Forms\Fields\Field_Base {
|
87 | 93 |
|
88 |
| - public function get_script_depends(): array { |
89 |
| - return [ 'field-script-1', 'field-script-2' ]; |
90 |
| - } |
| 94 | + public $depended_scripts = [ 'script-handle' ]; |
91 | 95 |
|
92 |
| - public function get_style_depends(): array { |
93 |
| - return [ 'field-style-1', 'field-style-2' ]; |
94 |
| - } |
| 96 | + public $depended_styles = [ 'style-handle' ]; |
95 | 97 |
|
96 | 98 | }
|
97 | 99 | ```
|
98 | 100 |
|
99 |
| -::: warning Please Note |
100 |
| -To make sure your current code is future campatible, make sure your form field class doesn't have the `get_script_depends()` and `get_style_depends()` methods. |
101 |
| -::: |
| 101 | +If you need to support Elementor versions prior to 3.29, add these properties to the form field class with the required script/style handles. |
0 commit comments