2

What I am trying to achieve it to show messages on a dialog form as asked and answered here. However, while the example above used the default editGridRow in the code, I have a custom dialog form loaded in via JSON. For example the JSON error/validation message returned could be:

{"CustomerName":{"isEmpty":"\u201cthis value is - not to be left empty.\u201d"}}

I need to be able to output them as "Customer Name - this value is not to be left empty" - at the top of the dialog form.

I have tried the solutions in A, B, C and D but I have not been able to customize them to work in my scenario yet.

I have a function call like so:

function LaunchEditForm(dialog) 
    {
        $('form', dialog).submit(function () 
        {
            $.ajax({
                url: '/customer/update-customer/',
                type: this.method,
                reloadAfterSubmit: true,    
                data: $(this).serialize(),
                success: function (result) 
                {
                    if (result.success) 
                    {
                        console.log(result);
                       //can I call a function here to prepend modal form
                       //with success message? how please?
                    } 
                    else 
                    {
                        console.log(result);
                        // can I prepend the dialog to show model errors here?
                        //var errorDetail = jQuery.parseJSON(result.responseText);
                    }
                }


            });
            return false;
        });
    }

I have tried using afterSubmit like so:

afterSubmit: function (response, postdata) 
                    {
                        if (response.responseText == "Success") 
                        {
                            jQuery("#success").show();
                            jQuery("#success").html("Customer successfully updated");
                            jQuery("#success").fadeOut(6000);
                            return [true, response.responseText]
                        }
                        else 
                        {
                            return [false, response.responseText]
                        }
                    }

This has not worked yet - perhaps I have placed it in a different scope

and also tried errorTextFormat like so:

errorTextFormat: function (data) 
                    {
                        if (data.responseText.substr(0, 6) == "<html ") 
                        {
                            return jQuery(data.responseText).html();
                        }
                        else 
                        {
                            return "Status: '" + data.statusText + "'. Error code: " + data.status;
                        }
                    }

Please help with this. I know I need some function that parses the JSON successfully and hopefully presents the errors and messages Oleg described

Community
  • 1
  • 1
pi.
  • 1,441
  • 3
  • 19
  • 25

0 Answers0