Skip to content

Conversation

@aguingand
Copy link
Contributor

@aguingand aguingand commented Aug 25, 2025

Allow to render Html field in forms depending on other data :

SharpFormHtmlField::make('publication_label')
    ->setLiveRefresh(linkedFields: ['published_at'])
    ->setTemplate(function (array $data) {
        if (! isset($data['published_at'])) {
            return '';
        }
        
        return 'This post will be published on '
            . \Carbon\Carbon::parse($data['published_at'])->isoFormat('LLLL');
    });

New method :

->setLiveRefresh(bool $liveRefresh = true, ?array $linkedFields = null)

When specified, the Html will be rerendered on each use input (debounce 200ms) (in addition of the initial render). $linkedFields allows to only call Sharp refresh endpoint when some fields has been changed (and not all).

setTemplate() now accepts a closure

->setTemplate(function (array $data) { })

$data is either root form data or if we are in a list: the item data.

The closure can return an HTML string or a view().

@aguingand aguingand merged commit b609652 into main Sep 1, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants