Back To Front

Components for creates All Backend Widgets in Frontend pages (Lists, Search, Filter, Forms, FormWidgets, MediaManager, Reports) and manage this items

Back to Back To Front Support

xtsidx
xtsidx

My form contains fields:

region:
    label: Region
    type: dropdown
    options: listRegions
district:
    label: District
    type: dropdown
    options: listDistricts
    dependsOn: region
city:
    label: City
    type: dropdown
    options: listCities
    dependsOn: district

Code in model:

public function listRegions($value, $data)
{
    $regions = Regions::getRegions();
    if($value) $regions[$value] = $value; // if not contain
    return $regions;
}

public function listDistricts($value, $data)
{
    $districts = Regions::getDistricts($this->region);
    if($value) $districts[$value] = $value; // if not contain
    return $districts;
}

public function listCities($value, $data)
{
    $cities = Regions::getCities($this->region, $this->district);
    if($value) $cities[$value] = $value; // if not contain
    return $cities;
}

In real backend this magic works perfectly, in backtofront no =(

I am forced to perform such a fix:

$('#Form-field-Offer-region').trigger('change');
$('#Form-field-Offer-district').trigger('change');

I found out that in my functions (listDistricts eg) $this is null when a call from BackToFront.

In real backend $this is model object.

The error is precisely at the initial filling of the elements. With manual clicking, this works just as well as in backend.

Last updated

Linkonoid
Linkonoid

Dropdown DependsOn work in little test (user select): https://backtofront.test.linkonoid.com/useraccount/userclientsmoneys/update/6

I add this Dropdown

    public function getUserIdOptions(){
        if ($this->user_clients){
            return [$this->user_clients->id];
        } else return [];
    }

Apparently the problem is in the empty value on initialization. Try without using options: list ...

Last updated

xtsidx
xtsidx

region is root of this depends tree, he is not empty, When checking all these fields have values.

I open the same object in backend and in backtofront: district in backend with elements, in backtofront no elements. $this is null in function listDistricts when call from backtofront.

backend page load

backtofront page load

backtofront after change trigger

Linkonoid
Linkonoid

Yes, obviously, the problem is in $this during initialization. It’s hard to say what the problem is, possibly in the backend, as in your case done through ".trigger ('change');" (most likely it is).

Сan also try the option to set the initial values ​​through

public function filterFields($fields, $context = null)....
AND
$this->bindEvent('model.beforeSetAttribute', function ($key, $value)...

I'll try, maybe something will come of this

Last updated

1-4 of 4