How do I adapt select fields dependant on the value of another field in Editor?
How do I adapt select fields dependant on the value of another field in Editor?
Hi,
I have two tables: job and step.
In step there is a reference to jobid (shown as select , which works great)
In step you can define a "follow-up" step. When clicking on that field (I chose "online editing")
there should be a select field - but only with those "steps" (stepnames) that have the same jobid as
the one that you just click on.
I tried it that way - but the "where" for followup_stepid does not work (it work if I i.e. define a fixed number - i.e. 1)
Editor::inst( $this->editorDb, 'tbladib_step', 'stepid' ) ->debug(true)
->field(
Field::inst( 'tbladib_step.jobid' )->setFormatter( 'Format::ifEmpty', null )
->options( Options::inst()
->table( 'tbladib_job' )
->value( 'jobid' )
->label( 'jobname' )
),
Field::inst( 'tbladib_job.jobname' ), // wichtig: Im Fall von foreignKeys immer BEIDE Werte nehmen!
Field::inst( 'tbladib_step.followup_stepid' )->setFormatter( 'Format::ifEmpty', null )
->options( Options::inst()
->table( 'tbladib_step' )
->value( 'stepid' )
->label( 'stepname' )
->where( function ($q) {
$q->where( 'tbladib_step.jobid', $post['data']['tbladib_step']['jobid'] );
})
),
Field::inst( 'refstep.stepname' ) // wichtig: Im Fall von foreignKeys immer BEIDE Werte nehmen!
)
->leftJoin( 'tbladib_job', 'tbladib_job.jobid', '=', 'tbladib_step.jobid' )
->leftJoin( 'tbladib_step as refstep', 'refstep.stepid', '=', 'tbladib_step.followup_stepid' )
->process($post)
->json();
}
How can I solve that??
Thanks a lot,
Pascal
Answers
Hi Pascal,
You need to use a cascading select as described here.
The issue here is that each row could have different options for the second select list, so the list of options must be available on a per row basis. Either you could modify the data to include that for each row, or use an Ajax request like in the blog post.
Allan
Hi Allan.
On the page you linked to, "Contient" should be "Continent".
I just can't help myself....
@allan: Thank you so much - it worked...
BUT:
What is the best way to avoid that the function is only called once when/if the user clicks on that selection field (currently it is called all the time).
I addded an event - but "mouseup" does not seem to be the best...
Thank you!
PAscal