jQWidgets Forums

jQuery UI Widgets Forums Grid Validation doesn't work

This topic contains 1 reply, has 2 voices, and was last updated by  Martin 6 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • Validation doesn't work #102818

    mathod
    Participant

    Hello,
    I have an other question…

    I don’t undertand why my validation doesn’t work…

    columns: any[] =
      [   
          { text: 'Name', datafield: 'name',width: 100, cellsalign: 'center',
            validation: function(cell,value){
    
              var validationResult = true;
    
              var rows = this.myGridTarif.getrows();
              
              for (var i = 0; i< rows.length;i++){
                if (i == cell.row)
                break;
                if (rows[i].name == value){
                  validationResult = false;
                  break;
                }
              };
    
              if( validationResult == false)
                return {result:false, message:"name must be unique"};
    
              return true;
            }
        
          },
          { text: 'Prix', datafield: 'prix',width: 100, cellsalign: 'center' },
      ];

    whatever i write in my cell named “name” it return me “Entered value is not valid” it’s a default return.. but i don’t understand why..
    i tried to debug, and it seems that var rows = this.myGridTarif.getrows(); doesn’t work… but don’t know why
    i followed already a tutorial, and it works when i don’t what use this command : var rows = this.myGridTarif.getrows();

    someone can tell me why it doesn’t work please?

    I have an other question :
    is it possible to put in cells of my grid an id, and display this the name wich worrespond to this id?
    for example my datafield name contain “1” and, it display in my grid “Hello” because id 1 is corresponding to hello ( and a function convert my id to the corresponding name)
    because i want to bind differents grid between them, and if i put the value and not the id, if i change a value on one grid, it not be changed in others…

    i don’t know if you see what i want to do

    Thanks a lot for your help an other time…

    Math

    Validation doesn't work #102839

    Martin
    Participant

    Hello Math,

    The issue with the validation is that the scope of the validation function is not the same as that of the component,
    so you don’t have access to this.myGridTarif there. You should change it to be an arrow function,
    so it doesn’t create its own scope.

    You can check the Example here.

    As for the id, there isn’t such functionality. However, you can bind to the cellvaluechanged event of the grids
    and update the other ones when one of them is edited.

    Best Regards,
    Martin

    jQWidgets Team
    http://www.jqwidgets.com/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.