# [Usage](../../../usage.md) > [Components and standard attributes](../basics.md) > progressBar

![image](img/progress_bar_1.png)

```php
Form::make()
    ->setSchema([
        Input::make('name')
    ])
    ->setProgressBar(function($data, $progress) {

        sleep(1);

        $newProgress = $progress + 20;

        return [
            'message' => '(' . $newProgress . '/100) done',
            'progress' => $newProgress,
        ];
    });
```

---
`progressBar` | `->setProgressBar()`

ProgressBar is a visual component valid only for `Form` components or `Modal` components with form implementation, and the target is to have a looped back-end function with front-end updates.

At the form submit, after verify and executing an eventual validation of fields, it will execute the `progressBar` function if defined.

Enabling the progressBar in modals will enable the form even without setting the URL.  
__IMPORTANT:__ If a Form has both progressBar and URL defined, at the end of progressBar execution it will be submitted to the request URL.

The closure can receive two arguments:
- `$data`: all the form fields value, to do manipulations
- `$progress`: is the actual progress number.

The closure can return 3 output:
- `true`: if true is returned, the progressBar loop ends and operation is successful.
- `false`: if false is returned, the progressBar loop ends and operation is not successful.
- `array`: the array accepts two keys, that are optional:
  - `progress`: is the progress value that must be passed to the next recursion
  - `message`: optional message displayed on top of the progressBar
  - `file`: you can return a file URL to download at each progress step, useful to chunking.
  - `params`: array, you can place here parameters to pass to the next cycle.

`$progress` has range from `0` to `100`, if progress value returned is greater or equal to 100, then the recursion will end and success message will be displayed.  

_NOTE:_ The progress can be any type of number.  
_NOTE 2_: For security reasons, each progress bar recursions is always delayed by minimum 50ms.  
_NOTE 3_: Be careful because this is a recursive function, and cannot end until `true` or `$progress` >= 100 is returned.

#### A progress bar can be canceled by the user by default, if you want to disable this behaviour you should use:  
`->setDisableCancelProgressbar()`

| Types     | Default |
|-----------|---------|
| `Closure` | `null`  |

Looped backend task with frontend progress for `Form` / `Modal` with form (imports, batch jobs). When omitted (`null`) submit follows the normal `url` / `action` path. Closure receives `($data, $progress)` and returns `true` / `false` or `['progress'=>n,'message'=>..,'file'=>..,'params'=>..]`; `>=100` ends successfully.
If both `progressBar` and `url` are set, progress runs first then posts to `url`.

### Example
Blade:
```php
{!! \KFramework\Components\Forms\Form::make()->setProgressBar(fn($data, $progress) => $progress >= 100 ? true : ['progress' => $progress + 20]) !!}
```
Controller:
```php
Form::make()->setSchema([Input::make('file')])->setProgressBar(fn($data, $progress) => ['progress' => $progress + 20]);
```

### Interaction / tips
- Chain with `url` (../shared_attributes/url.md) for progress-then-submit; with `action` (../shared_attributes/action.md) for post-progress logic.
- Disable user cancel via `->setDisableCancelProgressbar()`; confirm via `confirmationMessage` (../shared_attributes/confirmation_message.md).
- Cached per `uuid` (../shared_attributes/uuid.md); keep closures serializable.

See also: [action](action.md), [url](url.md), [confirmationMessage](confirmation_message.md), [uuid](uuid.md), [basics](../basics.md), [Form](../forms/form.md).