Editing and Mjoin
Editing and Mjoin
I have two tables with a one-to-many relationship. Regattas have a number of divisions based on how many races are being raced. That collection of divisions is a div_series. I am looking to display the div_series name as the collection of divisions and have the user be able to select a div_series by its name.
Editor
{
label: "division",
name: "division[].div_series",
render: "[, ].div_name",
type: "select"
}
DataTable
{ data: "division", render: "[, ].div_name", editField: "regatta.reg_div_series" },
Server Side
->join(
Mjoin::inst( 'division' )
->link( 'division.div_series', 'regatta.reg_div_series' )
->order( 'div_order ASC' )
->fields(
Field::inst( 'div_series' )
->validator( Validate::required() )
->options( Options::inst()
->table( 'division' )
->label( 'div_series' )
->value( 'div_series' )
->where( function ( $q ) use ( $user_assoc ) {
$q->where( 'div_end_year', '0', '=' );
$q->where( 'division.div_assoc_id', $user_assoc, '=' );
} )
),
Field::inst( 'div_name' )
)
)
A number of issues arise, and I apologise in advance if these are simple issues, this is the first time I have attempted to use Mjoin.
Datatables renders the column correctly, however when the column is clicked on i get the error "Uncaught Unable to automatically determine field from source. Please specify the field name. For more information, please refer to https://datatables.net/tn/11", however, I had already specified the editField.
When I select a row and invoke the editor the correct selection is made (only the div_series that are appropriate are displayed) but the select values render as the div_series number rather than the concatenated names?
When I submit a change from the editor I get:
"{"fieldErrors":[{"name":"division[].div_series","status":"Input not valid"}],"data":[]}"
I realise this is most likely my misunderstanding, however, any direction would be appreciated. Thanks in advance.
This question has an accepted answers - jump to answer
Answers
Right - but the field name given, doesn't match the name of the field given to Editor. In the DataTables config you've said edit
regatta.reg_div_series
, but in Editor you've called the fielddivision[].div_series
You want to have them match - see this example.
The label should be showing the
div_series
value since you use->label( 'div_series' )
. I think you probably want to change that line to be->label( 'div_name' )
.Allan
I was assuming that from a division table that looks like:
div_series,div_name
1,A; 2,AAAA;2,AA;2,A;1,B;2,AA;1,C
I could construct a select list
{ value: 1, label: "A, B, C"}, { value: 2, label: "AAAA, AAA, AA, A"}
that would assign name to regatta.reg_div_series when selected in both the inline editor and the editor window.
I don't quite understand the table data structure there. Did the change I suggested make any difference?
Allan
They made a difference, but still produce errors (that are related). The select list does not populate and of course produces the error "An SQL error occurred: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'reg_div_series' at row 1".
The data structure that is relevant:
When displaying Regatta from this data I want to the reg_div_series as, for example: "A,B,C" this works using
data: division, render: "[,].div_name"
I am looking for the select menu to comprise:
AAAA, AAA, AA, A
A, B, C
A, B
but to assign the div_series value to regatta.reg_div_series which in the example above would be:
1
2
3
Hope that is a little clearer. Thanks again!
So I bypassed the whole thing and build the options: list myself which works as expected, except for the fact that the current value is not automatically chosen from the options: list. I presume that this is because the current selected value is chosen as the list is being built rather than added after the list is constructed. Is there a standard way of setting the selected value to the current value?
The built in select field type should actually be able to handle that. Can you show me the code you are using please?
Allan
No worries, left over field data: reference from earlier attempt was messing it about.
Thanks!