platform
platform copied to clipboard
Listenened field clears.
Trying to implement a Dependent Dropdown. Seems to work fine except for a couple of issues
-
Need to initialise dependent dropdown first time into screen based on current district_id. I can probably work that out
-
BUT, immediately after selecting a district, the district dropdown clears!!! The Location dropdown is populated correctly with the locations for the selected district, but the District dropdown is clear! Been hitting my head against this for a while now. What is happening
Please help.
<--relevant code below-->
DistrictListener.php
class DistrictListener extends Listener
{
/**
* List of field names for which values will be listened.
*
* @var string[]
*/
protected $targets = ['event.district_id'];
/**
* What screen method should be called
* as a source for an asynchronous request.
*
* The name of the method must
* begin with the prefix "async"
*
* @var string
*/
protected $asyncMethod = 'asyncFromDistrict';
/**
* @return Layout[]
*/
protected function layouts(): iterable
{
// dump($this->query->get('location'));
return [
Layout::rows([
Select::make('event.district_id')
->title('District')
->fromModel(District::class, 'district_name')
->empty('--everywhere--'),
Select::make('event_id.location_id')
->title('Location')
->options($this->query->get('location')?$this->query->get('location'):[]),
}
EventEditScreen.php
public function asyncFromDistrict($district_id)
{
return [
'location' => Location::where('district_id',$district_id)->pluck('description','id')->toArray()
];
}
Can your provide the version of Orchid you are using please
I will close this for now as inactive.
Definitely not inactive. Sorry, been away for a few days. Using latest version of Orchid, latest laravel. Don't have development machine with me so can't quote version numbers sorry but first thing I did when I first had this problem was to make sure I was on latest versions.
you have to set the values in listener layout not to lose them. So, you have to listen for the values for all you put in your listener class.
for ex : if you put fields a, b, c in your Listener Layout, then you should listen fields a,b,c and set their own value inside listener class.