Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
250
IGGRID Custom validation dialog Angular 4
posted

Hi,

I need help to add custom validation to the account textbox inside dialog editor to see if the account exist in the database through API. I tried below code but i can't seem to get it to work.

{
  columnKey: "customerAcctNo",
  editorType: 'text',
  required: true,
  editorOptions: {
    validatorOptions: {
      custom: {
        method: function (value, fieldOps) {
          me._sharedService.validateAccount(value)
          .subscribe(data => {
           if (data) {return true;}
           else {return false;}})
        },
        errorMessage: "Account doesn't exist"
      }
    },
    width: "100%"
  }
},

SERVICE:

public validateAccount(account: string): Observable<IUser[]> {
let params: URLSearchParams = new URLSearchParams();
if (account) { params.set('customerAcctNo', account); }

let requestOptions = new RequestOptions();
requestOptions.withCredentials = true;
requestOptions.search = params;

return this._http.get(this._accountUrl, requestOptions)
.map((response: Response) => { if (response) { return true; } else { return false } })
.do(data => console.log('account: ' + JSON.stringify(data)))
.catch(this.handleError);
}