Validation on MultiEdit
Validation on MultiEdit
Hello,
I have setup a self-join in a checkbox. In this checkbox I can select table names, while the DB stores the corresponding table id . As this checkbox is an optional input field, I can also select the value 'None' and the DB should store 0 (zero). This all works fine when editing single records.
Problem: If I select two (or more) records for MultiEdit, while one record's checkbox is set to 'None' and the other's checkbox is NOT set to 'None', the validator does not let me save any change and throws the message "Input not valid".
This is my setup:
/* JAVASCRIPT File: */
var dt_tables_editor = new $.fn.dataTable.Editor( {
...
fields: [
{ "label": "db_table:", "name": "dt_tables.db_table", "type": "textarea" },
{ "label": "parent_table_id:", "name": "dt_tables.parent_table_id", "type": "select" , placeholder:"none", placeholderDisabled:false }
]
});
var dt_tables_table = $('#dt_tables').DataTable( {
...
columns: [
{ data: 'dt_tables.db_table' },
{ data: 'dt_tables2.db_table' }
]
});
/* PHP File: */
Editor::inst( $db, 'dt_tables', 'id' )
->fields(
Field::inst( 'dt_tables.db_table' ),
Field::inst( 'dt_tables.parent_table_id' )->options(Options::inst()->table('dt_tables')->value('id')->label('db_table'))->validator(Validate::dbValues()),
Field::inst( 'dt_tables2.db_table' )
)->leftJoin('dt_tables as dt_tables2','dt_tables2.id','=','dt_tables.parent_table_id')
->process( $_POST )
->json();
Is it possible to fix this issue so I can do MultiEdit somehow?
Best regards
marwi
This question has an accepted answers - jump to answer
Answers
Can you show me the data that is being submitted from the client-side please ("Network" inspector and then the "Headers" for the Ajax request).
The row validation should be done on a per row basis, even when multi-editing. So if both pass when single row editing, they should also pass when multi-row editing.
Allan
Hi Allan,
Sure this is the data. Please let me know if you need anything else to get the scenario.
I've got a feeling its the
0
value.Do you have another row where the
parent_table_id
is not0
and you can try updating that row and the5
row at the same time?Thanks,
Allan
Yes, this only happens if I mix 0 value and Non-0 value. If I update two rows with both having 0 value or two rows with both having Non-0 values, it works fine. But the mix throws the validation error. The 0-value is not an existing id in the table, but I use this value 0 for indicating that the user did select 'None' in the dropdown list, as this selection is optional.
I see - so the
0
isn't actually in the database table? Its odd that it passes at all when you submit a0
for that field then!The
dbValues
validator has the option of specifying extra values that are valid beyond just those used in the database. In this case you might use:(that
0
might need to be in quotes to make it a string....)Allan
Yes, it works now with those parameters you have provided. There is one comma missing before the [ 0 ].
However, also see that it's strange as the validator did not throw an error in case of single edit with 0 before. I also did not define any placeholderValue ... I'm not fully understanding the logic behind, but at least it work fine now, thanks for your great help!
Oops - thanks for spotting the error. I've edited it now.
Yes, I don't understand why it didn't throw an error for the single edit of a 0 value before either. I'll try to replicated that locally. It sounds like a
falsy
test error.Allan