Author Topic: How does the Validation work  (Read 4519 times)

ram

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 2
    • View Profile
How does the Validation work
« on: December 30, 2013, 09:57:54 am »
Param,

I'm having a similar issue. I have the validations set up for various columns but they don't fire automatically. So I tried explicitly invoking isValid on cellSave like this:

         j$("[id=custom_grid]").pqGrid({
             cellSave: function( event, ui ) {
               var colM=j$( "[id=custom_grid]" ).pqGrid( "option" , "colModel" );   
                    var isValid = j$("[id=custom_grid]").pqGrid( "isValid" , { rowIndx: ui.rowIndx, dataIndx: ui.dataIndx, value: ui.newVal } );
                   
                   if(isValid.valid == false) {
                      alert(ui.newVal + " " + colM[ui.dataIndx].validations[0].msg);
                  j$("[id=custom_grid]").pqGrid( "isValid" , { rowIndx: ui.rowIndx, dataIndx: ui.dataIndx, value: ui.newVal } );
                     
                    }                
                }
         });

When I try to tab to the next cell, it does pop up a message when the cell value is invalid but allows the value to be still there. Is there a way to just change the cell value to an empty string?

I also tried this:

         j$("[id=custom_grid]").on( "pqgridcellsave", function( event, ui ) {
             var isValid = j$("[id=custom_grid]").pqGrid( "isValid" , { rowIndx: ui.rowIndx, dataIndx: ui.dataIndx, value: ui.newVal } );

             if (!isValid) {
                 j$("[id=custom_grid]").find(".pq-editor-focus").css({ "border-color": "red" });
                 return false;
             }
             evt.stopPropagation();           
         });

On tabbing to the next cell, the validation fires but the cursor stays in the cell and I need to hover on the cell to see the validation error. Then I can move on to the next cell with the contents of the previous cell hidden but still containing the erroneous value. I wonder if I might be missing something in how the validations are supposed to work - I was hoping for something more automatic and that could stop you in your tracks if you entered an invalid value. If not, just being able to nullify the value may be the plan B here.

Thanks,
Ram

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: How does the Validation work
« Reply #1 on: December 30, 2013, 10:56:19 am »
Ram

Validations don't fire automatically, they need to be hooked up with an appropriate event in order to work.

cellSave event occurs after the cell is already saved, hence it's not an appropriate event to work with validations.

cellBeforeSave event occurs just before the cell is saved. Also when we return false from cellBeforeSave event, it prevents the cell from saving it's value from editor. Hence it's an appropriate event to work with validations.

Here is an example to setup validations with cellBeforeSave Event

http://paramquery.com/pro/demos/editing_custom

 
« Last Edit: December 30, 2013, 01:55:36 pm by paramquery »

ram

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How does the Validation work
« Reply #2 on: December 30, 2013, 10:59:01 am »
Param,

Thanks for the quick reply. I will try that. I was able to null out the cell in the data model on isValid = false. But I'll tie the validation to cellBeforeSave as you suggest.

Thanks!
Ram