# How to Use Dependency

## How to Use Dependency <a href="#how-to-use-dependency" id="how-to-use-dependency"></a>

#### Let’s take a look how to using dependency

### Demo

![](https://wpsf.github.io/s3/fields/deps.gif)

```php
// If text "not be empty"
array(
  'id'           => 'dep_1',
  'type'         => 'text',
  'title'        => 'If text not be empty',
),

array(
  'id'           => 'dummy_1',
  'type'         => 'notice',
  'class'        => 'info',
  'content'      => 'Done, this text option have something.',
  'dependency'   => array( 'dep_1', '!=', '' ),
),
```

```php
// If switcher mode "ON"
array(
  'id'           => 'dep_2',
  'type'         => 'switcher',
  'title'        => 'If switcher mode ON',
),

array(
  'id'           => 'dummy_2',
  'type'         => 'notice',
  'class'        => 'success',
  'content'      => 'Woow! Switcher is ON',
  'dependency'   => array( 'dep_2', '==', 'true' ),
),
```

```php
// If selected color is "black or white"
array(
  'id'           => 'dep_3',
  'type'         => 'select',
  'title'        => 'Select color black or white',
  'options'      => array(
    'blue'       => 'Blue',
    'yellow'     => 'Yellow',
    'green'      => 'Green',
    'black'      => 'Black',
    'white'      => 'White',
  ),
),

array(
  'id'           => 'dummy_3',
  'type'         => 'notice',
  'class'        => 'danger',
  'content'      => 'Well done!',
  'dependency'   => array( 'dep_3', 'any', 'black,white' ),
),
```

```php
// If radio selected is "No, Thanks"
array(
  'id'           => 'dep_4',
  'type'         => 'radio',
  'title'        => 'If set No, Thanks',
  'options'      => array(
    'yes'        => 'Yes, Please',
    'no'         => 'No, Thanks',
    'not-sure'   => 'I am not sure!',
  ),
  'default'      => 'yes'
),

array(
  'id'           => 'dummy_4',
  'type'         => 'notice',
  'class'        => 'info',
  'content'      => 'Uh why?!!!',
  'dependency'   => array( 'dep_4_no', '==', 'true' ),
  //'dependency' => array( '{ID}_{VALUE}', '==', 'true' ),
),
```

```php
// If checkbox selected is "danger"
array(
  'id'           => 'dep_5',
  'type'         => 'checkbox',
  'title'        => 'If checked danger',
  'options'      => array(
    'success'    => 'Success',
    'danger'     => 'Danger',
    'info'       => 'Info',
    'warning'    => 'Warning',
  ),
),

array(
  'id'           => 'dummy_5',
  'type'         => 'notice',
  'class'        => 'danger',
  'content'      => 'Danger!',
  'dependency'   => array( 'dep_5_danger', '==', 'true' ),
  //'dependency' => array( '{ID}_{VALUE}', '==', 'true' ),
),
```

```php
// If image select is "blue"
array(
  'id'           => 'dep_6',
  'type'         => 'image_select',
  'title'        => 'If check <u>Blue box</u>',
  'options'      => array(
    'green'      => 'green.png',
    'red'        => 'red.png',
    'yellow'     => 'yellow.png',
    'blue'       => 'blue.png',
    'gray'       => 'gray.png',
  ),
),

array(
  'id'           => 'dummy_6',
  'type'         => 'notice',
  'class'        => 'info',
  'content'      => 'Blue box selected!',
  'dependency'   => array( 'dep_6_blue', '==', 'true' ),
  //'dependency' => array( '{ID}_{VALUE}', '==', 'true' ),
),
```

```php
// If image select is "blue or green"
array(
  'id'           => 'dep_7',
  'type'         => 'image_select',
  'title'        => 'If check <u>Blue box or Green box</u>',
  'options'      => array(
    'green'      => 'green.png',
    'red'        => 'red.png',
    'yellow'     => 'yellow.png',
    'blue'       => 'blue.png',
    'gray'       => 'gray.png',
  ),
  'radio'        => true,
  'default'      => 'gray',
  'attributes'   => array(
    'data-depend-id' => 'dep_7',
  ),
),

array(
  'id'           => 'dummy_7',
  'type'         => 'notice',
  'class'        => 'info',
  'content'      => 'Blue box selected!',
  'dependency'   => array( 'dep_7', 'any', 'green,blue' ),
  //'dependency' => array( 'data-depend-id', 'any', 'value,value' ),
),
```

```php
// Multiple element dependencies
array(
  'id'           => 'dep_10',
  'type'         => 'text',
  'title'        => 'If text string <u>hello</u>',
),

array(
  'id'           => 'dep_11',
  'type'         => 'text',
  'title'        => 'and this text string <u>world</u>',
),

array(
  'id'           => 'dep_12',
  'type'         => 'checkbox',
  'title'        => 'and checkbox mode <u>checked</u>',
  'label'        => 'Check me!'
),

array(
  'id'           => 'dummy_10',
  'type'         => 'notice',
  'class'        => 'info',
  'content'      => 'Done, Multiple Dependencies worked.',
  'dependency'   => array( 'dep_10|dep_11|dep_12', '==|==|==', 'hello|world|true' ),
),
```

```php
// Another Multiple element dependencies
array(
  'id'           => 'dep_13',
  'type'         => 'select',
  'title'        => 'If color <u>black or white</u>',
  'options'      => array(
    'blue'       => 'Blue',
    'black'      => 'Black',
    'white'      => 'White',
  ),
),

array(
  'id'           => 'dep_14',
  'type'         => 'select',
  'title'        => 'If size <u>middle</u>',
  'options'      => array(
    'small'      => 'Small',
    'middle'     => 'Middle',
    'large'      => 'Large',
    'xlage'      => 'XLarge',
  ),
),

array(
  'id'           => 'dep_15',
  'type'         => 'select',
  'title'        => 'If text is <u>world</u>',
  'options'      => array(
    'hello'      => 'Hello',
    'world'      => 'World',
  ),
  'dependency'   => array( 'dep_13|dep_14', 'any|==', 'black,white|middle' ),
),

array(
  'id'           => 'dummy_11',
  'type'         => 'notice',
  'class'        => 'info',
  'content'      => 'Well done, Correctly!',
  'dependency'   => array( 'dep_15', '==', 'world' ),
),

array(
  'id'           => 'dep_14',
  'type'         => 'select',
  'title'        => 'If size <u>middle</u>',
  'Group 1' => array(
    'blue'   => 'Blue',
    'green'  => 'Green',
    'yellow' => 'Yellow',
    ),
  'Group 2' => array(
    'red'   => 'Red',
    'black' => 'Black',
    'white' => 'White',
    ),
),
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wpsf.gitbook.io/docs/faq/how-to-use-dependency.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
