iframe component
Hi
has anyone made a iframe field for the form builder ?
or is it is as simple as View::make('my_view',$data)?
2 Replies
you can do something like this:
$iframe = '<div class="rounded-lg overflow-hidden border border-gray-900">
<iframe class="w-full h-[300px]"
frameborder="0"
src="'.$video['src'].'"
title="'.$video['title'].'"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
</div>';
$videoSchema[] = Placeholder::make('video')
->label($video['title'])
->content(new HtmlString($iframe));
$iframe = '<div class="rounded-lg overflow-hidden border border-gray-900">
<iframe class="w-full h-[300px]"
frameborder="0"
src="'.$video['src'].'"
title="'.$video['title'].'"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
</div>';
$videoSchema[] = Placeholder::make('video')
->label($video['title'])
->content(new HtmlString($iframe));
I ended up with this:
and the view
<?php
namespace App\Classes\Filament;
use Filament\Forms\Components\View;
class IFrameView extends View
{
public $content;
public $title;
public function setTitle(string $value): static
{
$this->title = $value;
return $this;
}
public function setContent(string $value): static
{
$this->content = $value;
return $this;
}
public function isContentUrl()
{
// check to see if the content is a url
return filter_var($this->content, FILTER_VALIDATE_URL);
}
}
<?php
namespace App\Classes\Filament;
use Filament\Forms\Components\View;
class IFrameView extends View
{
public $content;
public $title;
public function setTitle(string $value): static
{
$this->title = $value;
return $this;
}
public function setContent(string $value): static
{
$this->content = $value;
return $this;
}
public function isContentUrl()
{
// check to see if the content is a url
return filter_var($this->content, FILTER_VALIDATE_URL);
}
}
@if($isContentUrl())
<iframe class="w-full h-full" src="{{$content}}" title="{{ $title ?? ''}}" ></iframe>
@else
<iframe class="w-full h-full" srcdoc="{{$content}}" title="{{ $title ?? '' }}"></iframe>
@endif
@if($isContentUrl())
<iframe class="w-full h-full" src="{{$content}}" title="{{ $title ?? ''}}" ></iframe>
@else
<iframe class="w-full h-full" srcdoc="{{$content}}" title="{{ $title ?? '' }}"></iframe>
@endif