Using BeforeShowForm and BeforeSubmit

Jun 19, 2013 at 12:48 AM
Edited Jun 19, 2013 at 1:28 AM
Hi Tomasz, i need use this two methods to implement a custom validation.
First when ShowForm i need show some hidden field.
I have this implementation:
addActionOptions: new JqGridNavigatorEditActionOptions {Url = Url.Action("UpdateGasto"), CloseAfterEdit = true, ClearAfterAdd = true, Width = 400, BeforeShowForm = "showForm", BeforeSubmit = "checkTotal"},
    function showForm() {
        var formId = document.forms['FrmGrid_Gastos'];
        $("#tr_ImpGrabado", formId).show();
        $("#tr_ImpNoGrabado", formId).show();
        $("#tr_Iva", formId).show();
        $("#tr_IngBrutos", formId).show();
        $("#tr_Observaciones", formId).show();
        $("#tr_Saldo", formId).hide();
        $("#tr_Total", formId).hide();
Second BeforeSubmit I need to check if the fields and ImpNoGrabado ImpGrabado contain any value.
Both fields are not required but it requires that at least one of them contains a valid data. Both fields are decimal
I have this implementation:
    function checkTotal(postdata) {
        var impGrabado = parseFloat(postdata.ImpGrabado);
        var impNoGrabado = parseFloat(postdata.ImpNoGrabado);
        return [true, ""];
        return [false, "Error"];
I have two questions:
first: the implementation of BeforeSubmit you seem correctly?
second: i need implement something like Oleg's answer on this question
Jun 23, 2013 at 12:33 PM

In general your implementation seems to be correct.

What is the issue with implementing Oleg's answer? The helper allows separate options for add and edit operations so you should be able to define to different BeforeSubmit.

In general is there any problem you have found here?

Tomasz Pęczek
Jun 28, 2013 at 8:03 PM
Tomasz sorry for the delay in response, at this time everything is working properly, when creating this discussion was javascript error, $.browser, but this error was related to another outdated library incompatible with jquery 1.9.

Additionally consult you there is a "better way" to hide and unhide fields, specifically I need the fields are hidden in the grid but are visible when adding or editing.
Jun 30, 2013 at 7:54 AM
Edited Jun 30, 2013 at 7:56 AM

There is a good approach for this scenario, but only in form editing. You can use HiddenInputAttribute to hide column from displaying and then set EditHidden property on JqGridColumnEditableAttribute to make that column visible in add/edit form.

Tomasz Pęczek