简体   繁体   English

jqGrid-表单编辑问题

[英]jqGrid - form editing issues

In the inline editing, before the editing be made, it creates internally an array ( savedRow ) and fill it with the values of the fields that are being editable, so I can access this values. 在内联编辑中,在进行编辑之前,它会在内部创建一个数组( savedRow ),并用可编辑字段的值填充该数组,以便我可以访问此值。

I'd like to know if in the form editing it has something similar to this, because I need to access the values of the fields before the editing will be completed to do a validation before the fields are "saved" in the database. 我想知道在表单编辑中是否具有与此类似的内容,因为在将字段“保存”在数据库中之前,我需要先访问字段的值,然后编辑才能完成以进行验证。

Someone could help me? 有人可以帮我吗?


EDITED : 编辑:

I'm posting here a part of my code (the code of one field), and I'm trying to validate in both way (inline editing and form editing). 我在这里发布了我的代码的一部分(一个字段的代码),并且试图以两种方式进行验证(内联编辑和表单编辑)。 For inline editing I'm validating using dataEvents and there I'm using savedRow to access the data that were not stored yet. 对于内联编辑,我正在使用dataEvents验证,并在其中使用savedRow来访问尚未存储的数据。 But when I try to edit using form editing because of the the use of savedRow, it shows me an error: savedRow is not defined . 但是当我由于使用saveRow而尝试使用表单编辑进行编辑时,它显示了一个错误: savedRow is not defined In the case of this field the editrules fits with what I want to do, but I don't know if this will occurs in all of those fields. 在此字段的情况下, editrules适合我想要做的事情,但是我不知道这是否会在所有这些字段中发生。

{ name: 'ac_fd', index: 'ac_fd', width: 50, editable: true,
  formatter: 'number', editrules: { number:true, required:true, minValue: 0.1,
  maxValue: 1.0 }, formatoptions: { decimalPlaces: 1, decimalSeparator: '.'},
     editoptions: {
        dataEvents: [ {
           type: 'blur', fn: function(e) {                        
              var savedrow  = $("#list").getGridParam('savedRow');
              console.log($(this).val());
              if($(this).val() != savedrow[0]['ac_fd']) {         
                 var eid='#' + savedrow[0]['id'] + '_ac_fd';   
                 var val_fd=$(this).val();
                 var fd_min=0.1;
                 var fd_max=1.0;

                 if( isNaN(val_fd) || val_fd > fd_max || val_fd < fd_min) {
                       setTimeout(function(){
                       $(eid).focus().select();
                    },600);


                    $(eid).qtip({
                       content: {
                          text: 'Fator de Demanda deve ser um <b>número</b>
                                 entre <b>' + fd_min.toFixed(1) + '</b> e <b>'
                                 + fd_max.toFixed(1) + '</b>.',
                          title: {
                             text: 'Atenção:',
                             button: true
                          }
                       },
                       show: {
                          event: false,

                          ready: true,

                          effect: function() {
                             $(this).stop(0, 1).fadeIn(400);
                          },

                          delay: 0,
                                                     },
                       hide: {
                          event: false,

                          effect: function(api) {
                             $(this).stop(0, 1).fadeOut(900).queue(function() {
                                 api.destroy();
                             });
                          },
                       },
                       style: {
                          classes: 'qtip-red qtip-rounded trif_tip_err',
                          tip: {
                             width: 10,
                             height:12
                          } 
                       },
                       position: {
                          my: 'bottom left',  
                          at: 'top center',
                       },

                       events: {
                          render: function(event, api) {
                             tip_timer.call(api.elements.tooltip, event);
                          }
                       }
                    });  

                 }       
              }        
           }           
        } ]            
     }                   
  },

So if dataEvents is common and used for the three forms of edit, where can I do this type of validation (using qtip too and I want that this validation be used in inline editing too)? 因此,如果dataEvents是通用的并且用于三种编辑形式,那么在哪里可以进行这种类型的验证(也使用qtip,并且我希望也将此验证用于内联编辑中)?

The reason why jqGrid save the editing row in interval savedRow parameter is because jqGrid modify the editing row in-place. 之所以jqGrid的保存时间间隔编辑行savedRow参数是因为jqGrid的修改就地编辑一行。 Only because of that inline editing and cell editing use interval savedRow parameter. 仅因为该内联编辑和单元格编辑使用了间隔savedRow参数。 Form editing don't modifies the original row of grid till the editing will be finished. 在完成编辑之前,表单编辑不会修改网格的原始行。 So no savedRow parameter are used by form editing. 因此,表单编辑不会使用任何savedRow参数。

If the form are closed or if the server response will contains some error HTTP code the new data entered by user will be not saved in the grid. 如果关闭表单,或者服务器响应中将包含一些错误的HTTP代码,则用户输入的新数据将不会保存在网格中。 So simple server side validation is typically enough. 因此,简单的服务器端验证通常就足够了。 If you want implement additional client side validation you can use editrules feature. 如果要实施其他客户端验证,则可以使用editrules功能。 Custom validation is typically enough. 自定义验证通常就足够了。 It can help validate one field of the form. 它可以帮助验证表单的一个字段。 If you need compare multiple fields of form during validation (if the value of one field defines valid values of another field) then one uses beforeCheckValues callback additionally. 如果您需要在验证期间比较表单的多个字段(如果一个字段的值定义了另一个字段的有效值),则可以另外使用beforeCheckValues回调。

UPDATED : Inside of fn event handler you can test whether it will be called inside of form editing or not. 更新 :在fn事件处理程序内部,您可以测试是否在表单编辑内部调用它。 There are many ways to do this. 有很多方法可以做到这一点。 For example you can test $(e.target).closest(".FormGrid").length > 0 . 例如,您可以测试$(e.target).closest(".FormGrid").length > 0 If it's true then the event is inside of form. 如果为真,则该事件在表单内部。 Additionally it's important to understand that the current editing row is not changed till successful saving on the server . 此外,重要的是要了解, 直到成功保存到服务器上,当前编辑行才被更改 So you can use any time getGridParam with "selrow" option to get the id of editing row and you can use getRowData or getCell to get the data from the grid before modification started (the same as savedrow ). 所以,你可以随时使用getGridParam"selrow"选项,以获取编辑行的id,你可以使用getRowDatagetCell从电网中获取数据变更前开始(作为同一savedrow )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM