set default value in select, based on previously submitted value
set default value in select, based on previously submitted value
I have an editor page for which i add a user reference from a select list.
What i would like to do is set the default of the select to the last user reference id selected, as often the data is input in batches, so it would be one less thing to fill in.
So far I have tried setting a session value on create, and use this session value as the default, but it doesn't seem to work unless the page is reloaded.
json source
if ( Editor::action( $_POST ) === Editor::ACTION_CREATE ) {
$_SESSION['sessionpatron'] = $_POST['data']['tblitem']['ItemPatronID'];
....
php page
fields: [ {
label: "Patron Name:",
name: "tblitem.ItemPatronID",
def: <?php echo (isset($_SESSION['sessionpatron'])?$_SESSION['sessionpatron']:1);?>,
type: "select"
},
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
The best way I can think of doing this is to use the
dependent()
method to know when the field's value changes, and thefield().def()
method to set the default when it does change. The one missing piece of that puzzle then is to have this operation oncreate
only - there currently isn't an API method which will tell us which mode Editor is in (I'll add one in the next release) but we can use events to get that information and set a local variable.Here is an example:
That will run on this page for the first field in the form if you want to see it in action.
Allan
Oh yeah !
I never would have worked that out, so I copied it and pasted it, changed the editor field name, and it works !!
Respect