Editor error handling api

Editor error handling api

TropicalistaTropicalista Posts: 6Questions: 0Answers: 0
edited September 2012 in General
Hi,

I need to create new record using editor api.

I create a form and use this to submit data:

[code]
editor.create( null, null, false );
editor.set( 'url', $('#myinput').val() );
editor.submit();

[/code]
This works great.

But I have set url field validation as url. If I try to submit a non-url string I get error: Uncaught TypeError: Cannot read property 'top' of null

Probably because there is no form to display with error. I don't know.

How can I solve this problem? I have client-side validation, but really server-side is best. So I need a way to display error message. It's possible?

What if I use

[code]
$(document).ready(function() {
var editor = new $.fn.Editor( {
"ajaxUrl": "php/index.php",
"domTable": "#example",
"ajax": function ( method, url, data, successCallback, errorCallback ) {
$.ajax( {
"type": method,
"url": url,
"data": data,
"dataType": "json",
"success": function (json) {
successCallback( json );
},
"error": function (xhr, error, thrown) {
errorCallback( xhr, error, thrown );
}
} );
}
} );
} );
[/code]


I could set an error handling function here? could someone give me help?

Replies

  • allanallan Posts: 63,395Questions: 1Answers: 10,451 Site admin
    The `submit` method has an option to pass in an error handling function (the second argument), so you can do that (there is an example in the documentation): http://editor.datatables.net/api/#submit . Let us know how you get on with that.

    Allan
  • TropicalistaTropicalista Posts: 6Questions: 0Answers: 0
    edited September 2012
    I have tried

    [code]
    editor.create( null, null, false );
    editor.set( 'url', 'ww.llo.li' );
    editor.submit( function () {
    alert( 'Form successfully submitted!' );
    }, function () {
    alert( 'Form encountered an error :-(' );
    }
    );

    [/code]

    but got same error.

    The error occurs in line 49 of datatables.editor.js

    [code]

    0
  • allanallan Posts: 63,395Questions: 1Answers: 10,451 Site admin
    Ah I see - yes, that doesn't quite work then unfortunately. There is indeed a small bug in Editor there which is causing the problem - as your rightly surmise it assumes that it will be able to display the failed field - but of course in this case it can't, and it tries to do that before call the error callback function.

    I've just committed the fix and it will be packaged up into the next Editor release (likely 1.2.2). I'm not 100% certain on a timeframe for the release yet, there are a few other things to be finalised for it, but if it drags out at all, I'll package 1.2.2 with this change.

    Regards,
    Allan
  • TropicalistaTropicalista Posts: 6Questions: 0Answers: 0
    Many thanks
This discussion has been closed.