Remi
Remi
FFilament
Created by Remi on 10/10/2023 in #❓┊help
Get in ->maxItems() doesnt work
I've got a multi-select form field, in which the user can select 1 or 5 items, based on previous select.
Forms\Components\Select::make('status')
->required()
->options(StatusEnum::collect()->translate())
->live(),

Forms\Components\Select::make('locations')
->translateLabel()
->multiple()
->preload()
->relationship('locations', 'name')
->required()
->maxItems(fn(Get $get) => $get('status') > StatusEnum::ALMOST_MOVING ? 1 : 5)
Forms\Components\Select::make('status')
->required()
->options(StatusEnum::collect()->translate())
->live(),

Forms\Components\Select::make('locations')
->translateLabel()
->multiple()
->preload()
->relationship('locations', 'name')
->required()
->maxItems(fn(Get $get) => $get('status') > StatusEnum::ALMOST_MOVING ? 1 : 5)
The status field is updated correctly, but the maxItems always stays the initial value. It isnt updated. Is this a bug? or am i doing something wrong?
3 replies
FFilament
Created by Remi on 10/9/2023 in #❓┊help
Repeater based on other iterations
I want to create a repeater that allows a user to attach multiple locations, but every locations only once. so far i got this:
Forms\Components\Repeater::make('clientLocations')
->label(__('Locations'))
->live()
->relationship()
->orderColumn('order')
->simple(
Forms\Components\Select::make('location_id')
->live()
->relationship('location', 'name')
->required()
),
Forms\Components\Repeater::make('clientLocations')
->label(__('Locations'))
->live()
->relationship()
->orderColumn('order')
->simple(
Forms\Components\Select::make('location_id')
->live()
->relationship('location', 'name')
->required()
),
This allows me to create multiple attachments, but i can attach every location multiple times. i got this far, but this removes all the attached locations
Forms\Components\Repeater::make('clientLocations')
->label(__('Locations'))
->live()
->relationship()
->orderColumn('order')
->simple(
Forms\Components\Select::make('location_id')
->live()
->relationship('location', 'name', function (Builder $query, Get $get) {
Log::info(json_encode($get('../../clientLocations')));
return $query->whereNotIn('id',array_column($get('../../clientLocations'), 'location_id'));
})
->required()
),
Forms\Components\Repeater::make('clientLocations')
->label(__('Locations'))
->live()
->relationship()
->orderColumn('order')
->simple(
Forms\Components\Select::make('location_id')
->live()
->relationship('location', 'name', function (Builder $query, Get $get) {
Log::info(json_encode($get('../../clientLocations')));
return $query->whereNotIn('id',array_column($get('../../clientLocations'), 'location_id'));
})
->required()
),
5 replies
FFilament
Created by Remi on 10/9/2023 in #❓┊help
Repeater BelongsToMany not working on edit form
i followed the steps from the docs: https://filamentphp.com/docs/3.x/forms/fields/repeater#integrating-with-a-belongstomany-eloquent-relationship This works on creation, but on the edit form it only shows a single record, not all the items. On the Client Resource:
Forms\Components\Repeater::make('clientLocations')
->relationship()
->simple(
Forms\Components\Select::make('location_id')
->relationship('location', 'name')
->required()
)
->columns(1),
Forms\Components\Repeater::make('clientLocations')
->relationship()
->simple(
Forms\Components\Select::make('location_id')
->relationship('location', 'name')
->required()
)
->columns(1),
ClientLocation Pivot model has:
public function client(): BelongsTo
{
return $this->belongsTo(Client::class);
}

public function location(): BelongsTo
{
return $this->belongsTo(Location::class);
}
public function client(): BelongsTo
{
return $this->belongsTo(Client::class);
}

public function location(): BelongsTo
{
return $this->belongsTo(Location::class);
}
Also when I submit the edit page and change the single record it shows, it gives an error:
update
`client_location`
SET
`location_id` = 3
WHERE
`` = 39
AND `` = 39
update
`client_location`
SET
`location_id` = 3
WHERE
`` = 39
AND `` = 39
7 replies
FFilament
Created by Remi on 10/2/2023 in #❓┊help
live fields updating other field lags and created mistakes
I have a "name" field which is reactive and on updating this field, the slug field is updated to a slugified version of this field. But since v3, there appears to be a lag on updating, and when you type fast, letters get lost and the words get messed up. the code:
Forms\Components\TextInput::make('name')
->live()
->required()
->string()
->maxLength(250)
->afterStateUpdated(function ($state, Forms\Set $set) {
$slug = Str::slug($state);
$set('slug', '/' . $slug);
}),

Forms\Components\TextInput::make('slug')
->required(),
Forms\Components\TextInput::make('name')
->live()
->required()
->string()
->maxLength(250)
->afterStateUpdated(function ($state, Forms\Set $set) {
$slug = Str::slug($state);
$set('slug', '/' . $slug);
}),

Forms\Components\TextInput::make('slug')
->required(),
attached is a video of the error. Any ideas?
5 replies
FFilament
Created by Remi on 4/6/2023 in #❓┊help
Render Single Table action on different place
My table has multiple TableHeaderActions. 1 want all of them on the place they render by default, except one. Which i want to render elsewhere. So far i found
{!! Action::make('action')->requiresConfirmation()->action(fn() => dd('action works'))->toHtml() !!}
{!! Action::make('action')->requiresConfirmation()->action(fn() => dd('action works'))->toHtml() !!}
It renders the button where i want, but it doesnt work. Only when i add this button to the tableHeaderActions as well, it works. But then it is rendered in both places. It's like the modal doesnt render like this. I tried to
@include(Action::make('action')->requiresConfirmation()->action(fn() => dd('action works'))->getView())
@include(Action::make('action')->requiresConfirmation()->action(fn() => dd('action works'))->getView())
But that gives me errors about the $action variable not being set. I get that the button i render has wire:click="mountTableAction('action')" and its not in de table action array. So is there a way to include it in the tableaction array, but not have it render with the rest? Question: How do i render 1 tableHeaderAction in a different place from the rest?
5 replies
FFilament
Created by Remi on 3/23/2023 in #❓┊help
Label on form field, custom view
Im trying to use my own view for the label of a select form field.
public function label(string | Htmlable | Closure | null $label): static
{
$this->label = $label;

return $this;
}
public function label(string | Htmlable | Closure | null $label): static
{
$this->label = $label;

return $this;
}
Label accepts Htmlable and Closure, so i'm thinking this should be possible. But when i use:
Select::make('type')
->label(fn() => view('forms.components.label-with-tooltip'))
Select::make('type')
->label(fn() => view('forms.components.label-with-tooltip'))
It just escapes the HTML and prints the output. Is this possible? and how?
3 replies
FFilament
Created by Remi on 3/21/2023 in #❓┊help
Detect of sortable has been turn on or off on column
I want to do different things based on if a sort on a column has been turned on or off.
TextColumn::make('first_name')->sortable(),
TextColumn::make('first_name')->sortable(),
if the column is sorted either asc or desc, i want to update a bool variable to true on the Livewire component, if the sort is in its idle state, it want to update the variable to false. Is there a way for me to detect this? The docs describe this callback, but cant figure out if there is an "on" and "off" option to detect?
->sortable(query: function (Builder $query, string $direction): Builder {
return $query
->orderBy('last_name', $direction)
->orderBy('first_name', $direction);
})
->sortable(query: function (Builder $query, string $direction): Builder {
return $query
->orderBy('last_name', $direction)
->orderBy('first_name', $direction);
})
3 replies
FFilament
Created by Remi on 3/17/2023 in #❓┊help
Select form component position function not working
v2.16.51 merged the "position()" function on the select. Allowing you to put the dropdown above (top) or below (bottom) the input. https://github.com/filamentphp/filament/pull/4953/files But it doesn't seem to work (anymore). When i use ->position('top'), the dropdown is still at the bottom.
.choices__list--dropdown,
.choices__list[aria-expanded] {
@apply invisible absolute top-full z-[1] mt-2 w-full overflow-hidden break-words rounded-lg border border-gray-300 bg-white shadow-sm will-change-[visibility];
}
.choices__list--dropdown,
.choices__list[aria-expanded] {
@apply invisible absolute top-full z-[1] mt-2 w-full overflow-hidden break-words rounded-lg border border-gray-300 bg-white shadow-sm will-change-[visibility];
}
In the CSS the top-full class puts it always below the input. i believe this should change to bottom-full based on the position attribute of the field. Am i correct? or am i missing something?
9 replies
FFilament
Created by Remi on 3/16/2023 in #❓┊help
Preloaded select component loads selected values
Trying to figure out if this is a bug or if i'm doing something wrong. I have a select component with a relationship
Select::make('managers')
->relationship('managers', 'full_name')
->multiple()
->preload(),
Select::make('managers')
->relationship('managers', 'full_name')
->multiple()
->preload(),
When i use the form->fill it selects the current selected items, which works, but it also adds these to the drop down. These items are unresponsive in the dropdown. When i remove an item, and reselect it in the dropdown, it is removed from the dropdown. My expected behavior would be: on load, the currently selected items, are removed from the dropdown and only readded when the selection is removed.
2 replies