Editor - options function reference another field, is it possible?

Editor - options function reference another field, is it possible?

borconiborconi Posts: 56Questions: 19Answers: 1

I have the following fields:

Field::inst( 'company.Name' )->set(false),
        Field::inst( 'stores.short_add' )->set(false),
        Field::inst( 'jobs.description' )->options( 'job_descriptions', 'id', 'long_description', function ($q) {
                                    global $owner;
                                    $q->where('owner',$owner);})
                                    ->validator( 'Validate::dbValues' ),
        Field::inst( 'job_descriptions.short_description' )->set(false),
        Field::inst( 'jobs.startdate' )->set(false),
        Field::inst( 'clients.Company_Name' )->set(false),
        Field::inst( 'operatives.name' )->set(false),
        Field::inst( 'jobs.freq' )->set(false),
        Field::inst( 'jobs.job_end'),
        Field::inst( 'jobs.owner')

What I'm looking to achieve/do is have the subquery filtering based on the filed value (join) something like:

Field::inst( 'company.Name' )->set(false),
        Field::inst( 'stores.short_add' )->set(false),
        Field::inst( 'jobs.description' )->options( 'job_descriptions', 'id', 'long_description', function ($q) {
                                    
                                    $q->where('owner',jobs.owner);})
                                    ->validator( 'Validate::dbValues' ),
        Field::inst( 'job_descriptions.short_description' )->set(false),
        Field::inst( 'jobs.startdate' )->set(false),
        Field::inst( 'clients.Company_Name' )->set(false),
        Field::inst( 'operatives.name' )->set(false),
        Field::inst( 'jobs.freq' )->set(false),
        Field::inst( 'jobs.job_end'),
        Field::inst( 'jobs.owner')

Is that possible? If yes how?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,819Questions: 1Answers: 10,517 Site admin

    Not directly. The short hand options for the Field->options() doesn't allow for joining to a different table. What you would need to do instead is pass a closure in to Field->options() that would query the database and get the list of options.

    Regards,
    Allan

  • borconiborconi Posts: 56Questions: 19Answers: 1

    Thank you Allan.

    The question is how can I pass a Field::instance value to the closure function. Let's say I will like to use the Field::inst( 'jobs.owner') value in the

    Field::inst('my.filed')-> ->options( 'sites', 'id', 'name', function ($q) { $q->where( 'name', jobs.owner, 'LIKE' ); } );

    Is it possible or am I trying to accomplish something what currently is not supported.

  • allanallan Posts: 63,819Questions: 1Answers: 10,517 Site admin
    Answer ✓

    Oh I see - so the options should be different based on another field's value?

    For that you would need to use dependent() and have it make an Ajax request whenever the other field's value is changed. That Ajax request would return the options for that specific value.

    Allan

This discussion has been closed.