---
title: "validateToolbarItem(in:validationHandler:)"
framework: safariservices
role: symbol
role_heading: Instance Method
path: "safariservices/sfsafariextensionhandling/validatetoolbaritem(in:validationhandler:)"
---

# validateToolbarItem(in:validationHandler:)

Determines if a toolbar menu item should be enabled or have badge text when browser state changes.

## Declaration

```swift
optional func validateToolbarItem(in window: SFSafariWindow, validationHandler: @escaping (Bool, String) -> Void)
```

## Parameters

- `window`: The window containing the clicked toolbar item.
- `validationHandler`: A code block used to set the state of the toolbar item.

## Mentioned in

Adjusting settings for a toolbar item

## Discussion

Discussion This method is called by the setToolbarItemsNeedUpdate() method or when Safari’s state changes in a way that may affect the toolbar item’s enabled or badge state. Your handler should decide whether the toolbar menu should be enabled and whether it should have any badge text, and then call the validationHandler block to update the toolbar item state.

## See Also

### Working with Toolbar Items

- [toolbarItemClicked(in:)](safariservices/sfsafariextensionhandling/toolbaritemclicked(in:).md)
