You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code is causing me a headache, we have a hidden toggle to hold a bool, we trigger that to switch via a suffix action, intent is to toggle the query functionality in a select field - the addition of
->where(function ($query) use ($get) {
if (!$get('search_all_contacts') && $get('customer_id')) {
$query->where('customer_id', $get('customer_id'));
}
})
causes the ->preload to break the site once the suffix button is clicked, symptom is the appearance of a black box that covers most of the screen. If I remove the preload it works, and if I remove the code with the conditional where clause from the query, then preload works fine.
Select::make('primary_contact_id')
->label(__('Primary contact_2'))
->relationship(
'customer.contacts',
'full_name',
fn(Builder $query, Get $get) => $query
->with('customer')
->where('active', true)
->where(function ($query) use ($get) {
if (!$get('search_all_contacts') && $get('customer_id')) {
$query->where('customer_id', $get('customer_id'));
}
})
->orderBy('full_name')
)
->getOptionLabelFromRecordUsing( //breaks site if we add preload - for some unknown reason, symptom, black screen when flipping search_all_contacts bool
fn(Contact $record) => "{$record->full_name}, {$record->customer?->name}"
)
->suffixAction(
HintAction::make('search_all') // here Don't let the HintAction alias confuse you, it's the alias for actions in our form - started with just being for HintActions
->label(fn(Get $get) => $get('search_all_contacts') ? __('All contacts') : __('Customer contacts'))
->icon(fn(Get $get) => $get('search_all_contacts') ? 'heroicon-o-users' : 'heroicon-o-user')
->action(function (Set $set, Get $get) {
$set('search_all_contacts', !$get('search_all_contacts')); // Toggles between true/false
$set('primary_contact_id', null); // Resets the primary_contact_id
})
)
->searchable() //if we want to enable customer search as well we probably need to use getSearchResultsUsing (see documentation)
->HintAction(function (Get $get) {
$contactId = $get('primary_contact_id');
if ($contactId) {
return HintAction::make('open_contact')
->label('')
->tooltip(__('Open') . ' ' . __('contact'))
->url('/projects/contacts/' . $contactId . '/edit')
->openUrlInNewTab()
->icon('heroicon-o-arrow-top-right-on-square');
}
return null;
})
// ->preload()
->live(),
Toggle::make('search_all_contacts') //exist only to enable the suffix action on primary_contact_id
->afterStateHydrated(function (Set $set) {
$set('search_all_contacts', false);
})
->hidden()
->live(),
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Package
Form builder
Package Version
v3.2.124
How can we help you?
The following code is causing me a headache, we have a hidden toggle to hold a bool, we trigger that to switch via a suffix action, intent is to toggle the query functionality in a select field - the addition of
causes the ->preload to break the site once the suffix button is clicked, symptom is the appearance of a black box that covers most of the screen. If I remove the preload it works, and if I remove the code with the conditional where clause from the query, then preload works fine.
Beta Was this translation helpful? Give feedback.
All reactions