Author Topic: custom validation  (Read 3109 times)

unixgeri

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 2
    • View Profile
custom validation
« on: July 05, 2014, 07:32:13 am »
how can i define a custom validation function, whith custom parameters
and custom msg.

for example

function taxnumberIsValid(value,country) {
......
}

...
{ title: "country"},
{ title: "tax number",
    validations: ????????
}

Thanks in advance!

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6264
    • View Profile
Re: custom validation
« Reply #1 on: July 05, 2014, 10:55:01 am »
Pass ui parameter to the callback function which may be anonymous or a named function.

function taxnumberIsValid( ui ){
     var country = ui.rowData["country"],
           value = ui.value; //value is taxno as entered in the editor
     //do the validation and if it fails assign message to ui.msg and return false
     if( validation fails ){
        ui.msg = "some message";     
        return false;
     }
}

{ title: "Country", dataIndx: "country" },
{ title: "tax number", dataIndx: "taxno",
  validations: [ { type: taxnumberIsValid }]
}

Reference: http://paramquery.com/pro/api#option-column-validations
Example: http://paramquery.com/pro/demos/editing_custom Books column
« Last Edit: July 05, 2014, 11:00:35 am by paramquery »