onPreSubmit doesn't seem to work for me...
onPreSubmit doesn't seem to work for me...
I am trying to have some sort of control on the table data before sending to the server and so I decided to use onPreSubmit.
To check if I was doing right, I tried the following:
[code]
var editor;
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": tUrl, // php
"domTable": "…",
"fields": [ …]
});//end editor
...
...
editor.on ( 'onPreSubmit',
function (e, data) {
var d = data.nome;
alert("hey, you are " + d +"!");
return false; // just to be safe
}
);
});//end $.(document).ready
[/code]
When clicking the submit button on editor's form, I expected to see an alert with the message "hey, you are -name on the form- !",
but the alert message instead says: "hey, you are undefined!"
'nome' is a field which is correctly loaded and displayed both in the table and in editor's form.
…I can't understand why the 'data.nome' property turns out to be undefined.
What am I doing wrong?
To check if I was doing right, I tried the following:
[code]
var editor;
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajaxUrl": tUrl, // php
"domTable": "…",
"fields": [ …]
});//end editor
...
...
editor.on ( 'onPreSubmit',
function (e, data) {
var d = data.nome;
alert("hey, you are " + d +"!");
return false; // just to be safe
}
);
});//end $.(document).ready
[/code]
When clicking the submit button on editor's form, I expected to see an alert with the message "hey, you are -name on the form- !",
but the alert message instead says: "hey, you are undefined!"
'nome' is a field which is correctly loaded and displayed both in the table and in editor's form.
…I can't understand why the 'data.nome' property turns out to be undefined.
What am I doing wrong?
This discussion has been closed.
Replies
Allam
I was going along with the example shown on the API page regarding events fired by Editor:
[code]
// Client-side validation using onPreSubmit
editor.on( 'onPreSubmit', function (e, data) {
if ( data.name === "" ) {
this.error('name', 'A name must be given');
return false;
}
else if ( data.name.length >= 10 ) {
this.error('name', 'The name length must '+
'be less that 10 characters');
return false;
}
// ... additional fields could be checked here
} );
[/code]
..obviously, I was missing something about the object's structure..
Michele
This example shows how it should work:
http://editor.datatables.net/release/DataTables/extras/Editor/examples/clientValidation.html
I'll fix that page forthwith (edit - now done).
Thanks,
Allan
Huge documentation. Beautiful job.
regards,
Michele
(and now.. back to my regex headaches..(: )