Skip to content

Commit 2db62fe

Browse files
Update form field dependencies
1 parent ff0e55d commit 2db62fe

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

Diff for: src/form-fields/field-dependencies.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@
22

33
<Badge type="tip" vertical="top" text="Elementor Pro" /> <Badge type="warning" vertical="top" text="Advanced" />
44

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.
66

77
## Dependency Properties
88

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:
1010

1111
```php
1212
class Elementor_Test_Field extends \ElementorPro\Modules\Forms\Fields\Field_Base {
1313

14-
public $depended_scripts = [ 'script-handle' ];
14+
public function get_script_depends(): array {
15+
return [ 'script-handle' ];
16+
}
1517

16-
public $depended_styles = [ 'style-handle' ];
18+
public function get_style_depends(): array {
19+
return [ 'style-handle' ];
20+
}
1721

1822
}
1923
```
2024

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.
2226

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.
2428

2529
## Registering Scripts & Styles in WordPress
2630

@@ -69,33 +73,29 @@ Then, each form field should set its dependencies as follows:
6973
```php
7074
class Elementor_Test_Field extends \ElementorPro\Modules\Forms\Fields\Field_Base {
7175

72-
public $depended_scripts = [ 'field-script', 'external-library' ];
76+
public function get_script_depends(): array {
77+
return [ 'field-script', 'external-library' ];
78+
}
7379

74-
public $depended_styles = [ 'field-style', 'external-framework' ];
80+
public function get_style_depends(): array {
81+
return [ 'field-style', 'external-framework' ];
82+
}
7583

7684
}
7785
```
7886

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
8288

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:
8490

8591
```php
8692
class Elementor_Test_Field extends \ElementorPro\Modules\Forms\Fields\Field_Base {
8793

88-
public function get_script_depends(): array {
89-
return [ 'field-script-1', 'field-script-2' ];
90-
}
94+
public $depended_scripts = [ 'script-handle' ];
9195

92-
public function get_style_depends(): array {
93-
return [ 'field-style-1', 'field-style-2' ];
94-
}
96+
public $depended_styles = [ 'style-handle' ];
9597

9698
}
9799
```
98100

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.

Diff for: src/form-fields/field-structure.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ As mentioned above, Elementor form fields extend the `\ElementorPro\Modules\Form
2020
```php
2121
class Elementor_Test_Field extends \ElementorPro\Modules\Forms\Fields\Field_Base {
2222

23-
public $depended_scripts = [];
24-
25-
public $depended_styles = [];
26-
2723
public function get_type(): string {}
2824

2925
public function get_name(): string {}
3026

27+
public function get_script_depends(): array {}
28+
29+
public function get_style_depends(): array {}
30+
3131
public function render( $item, $item_index, $form ): void {}
3232

3333
public function validation( $field, $record, $ajax_handler ): void {}
@@ -39,14 +39,14 @@ class Elementor_Test_Field extends \ElementorPro\Modules\Forms\Fields\Field_Base
3939

4040
Let’s break it down:
4141

42-
* **Field Scripts** – The `$depended_scripts` property defines the JS files required to display the field.
43-
44-
* **Field Styles** – The `$depended_styles` property defines the CSS files required to display the field.
45-
4642
* **Field Type** – The `get_type()` method returns the field name (id) that will be used in the code.
4743

4844
* **Field Name** – The `get_name()` method returns the field label that will be displayed to the user.
4945

46+
* **Field Scripts** – The `get_script_depends()` method defines the JS files required to display the field.
47+
48+
* **Field Styles** – The `get_style_depends()` method defines the CSS files required to display the field.
49+
5050
* **Field Render** – The `render()` method renders the data and displays the field output.
5151

5252
* **Field Validation** – The `validation()` method runs a series of checks to ensure the data complies to certain rules.

0 commit comments

Comments
 (0)