@@ -245,7 +245,11 @@ function TForm2.ValidationTab2: IDataValidatorJSONResult;
245
245
246
246
.Value
247
247
.Trim
248
- .&Not .IsEmpty.WithMessage(' O ${key} deve ser informado!' )
248
+ .IsOptional(
249
+ function(const AValue: TJSONValue): Boolean
250
+ begin
251
+ Result := AValue.Null;
252
+ end )
249
253
.IsJSONString.WithMessage(' ${key} - ${value} - Não é do tipo string!' )
250
254
.IsLength(10 ,10 ).WithMessage(' ${key} - Deve ter somente 10 caracteres!' )
251
255
.IsDate(False).WithMessage(' ${key} - ${value} - Não é uma data válida!' )
@@ -375,84 +379,85 @@ function TForm2.ValidationTab2: IDataValidatorJSONResult;
375
379
.IsEmail.WithMessage(' ${key} - ${value} - Não é um e-mail válido!' )
376
380
.&End
377
381
.&End
382
+ ;
378
383
379
- .Validate(' items' )
380
- .Key
381
- .IsRequired.WithMessage(' Informe a key ${key}' )
382
- .&End
384
+ LResult := LJSONResult.Check;
383
385
384
- .Value
385
- .IsJSONObject.WithMessage(' ${key} - Não é do tipo JSONObject!' )
386
- .CustomJSONSubValidator(
387
- function(const AValue: IDataValidatorJSON; var AMessage: TDataValidatorMessage): Boolean
388
- var
389
- LJSONResult: IDataValidatorJSONResult;
390
- LResult: IDataValidatorResult;
391
- begin
392
- LJSONResult :=
393
- AValue
394
- .Validate(' product_id' )
395
- .Key
396
- .IsRequired.WithMessage(' Informe a key ${key}' )
397
- .&End
386
+ Result := LResult.OK;
398
387
399
- .Value
400
- .Trim
401
- .&Not .IsEmpty.WithMessage(' O ${key} deve ser informado!' )
402
- .IsJSONNumeric.WithMessage(' ${key} - ${value} - Não é do tipo numeric!' )
403
- .IsGreaterThan(0 ).WithMessage(' O ${key} deve ser maior que zero!' )
404
- .IsInteger.WithMessage(' O ${key} deve ser do tipo inteiro!' )
405
- .&End
406
- .&End
388
+ if not Result then
389
+ AMessage := LResult.Informations.GetItem(0 ).Messages;
390
+ end )
407
391
408
- .Validate(' product_name' )
409
- .Key
410
- .IsRequired.WithMessage(' Informe a key ${key}' )
411
- .&End
392
+ .&End
393
+ .&End
412
394
413
- .Value
414
- .Trim
415
- .&Not .IsEmpty.WithMessage(' O ${key} deve ser informado!' )
416
- .IsJSONString.WithMessage(' ${key} - ${value} - Não é do tipo string!' )
417
- .IsAlphaNumeric(TDataValidatorLocaleLanguage.tl_pt_BR, [' -' , ' ,' , ' /' , ' \' ]).WithMessage(' ${key} - ${value} - Não é um valor AlphaNumeric!' )
418
- .&End
419
- .&End
395
+ .Validate(' items' )
396
+ .Key
397
+ .IsRequired.WithMessage(' Informe a key ${key}' )
398
+ .&End
420
399
421
- .Validate(' price' )
422
- .Key
423
- .IsRequired.WithMessage(' Informe a key ${key}' )
424
- .&End
400
+ .Value
401
+ .IsJSONArray.WithMessage(' ${key} - Não é do tipo JSONArray!' )
402
+ .CustomJSONSubValidator(
403
+ function(const AValue: IDataValidatorJSON; var AMessage: TDataValidatorMessage): Boolean
404
+ var
405
+ LJSONResult: IDataValidatorJSONResult;
406
+ LResult: IDataValidatorResult;
407
+ begin
408
+ LJSONResult :=
409
+ AValue
410
+ .Validate(' product_id' )
411
+ .Key
412
+ .IsRequired.WithMessage(' Informe a key ${key}' )
413
+ .&End
425
414
426
- .Value
427
- .Trim
428
- .&Not .IsEmpty.WithMessage(' O ${key} deve ser informado!' )
429
- .IsNumeric.WithMessage(' O ${key} não é um valor inválido!' )
430
- .IsGreaterThan(-1 ).WithMessage(' Informe um valor maior que Zero!' )
431
- .&End
432
- .&End
415
+ .Value
416
+ .Trim
417
+ .&Not .IsEmpty.WithMessage(' O ${key} deve ser informado!' )
418
+ .IsJSONNumeric.WithMessage(' ${key} - ${value} - Não é do tipo numeric!' )
419
+ .IsGreaterThan(0 ).WithMessage(' O ${key} deve ser maior que zero!' )
420
+ .IsInteger.WithMessage(' O ${key} deve ser do tipo inteiro!' )
421
+ .&End
422
+ .&End
433
423
434
- .Validate(' quantity ' )
435
- .Key
436
- .IsRequired.WithMessage(' Informe a key ${key}' )
437
- .&End
424
+ .Validate(' product_name ' )
425
+ .Key
426
+ .IsRequired.WithMessage(' Informe a key ${key}' )
427
+ .&End
438
428
439
- .Value
440
- .Trim
441
- .&Not .IsEmpty.WithMessage(' O ${key} deve ser informado!' )
442
- .IsNumeric .WithMessage(' O ${key} não é um valor inválido !' )
443
- .& End
444
- .&End
445
- ;
429
+ .Value
430
+ .Trim
431
+ .&Not .IsEmpty.WithMessage(' O ${key} deve ser informado!' )
432
+ .IsJSONString .WithMessage(' ${key} - ${value} - Não é do tipo string !' )
433
+ .IsAlphaNumeric(TDataValidatorLocaleLanguage.tl_pt_BR, [ ' - ' , ' , ' , ' / ' , ' \ ' ]).WithMessage( ' ${key} - ${value} - Não é um valor AlphaNumeric! ' )
434
+ .&End
435
+ .& End
446
436
447
- LResult := LJSONResult.Check;
437
+ .Validate(' price' )
438
+ .Key
439
+ .IsRequired.WithMessage(' Informe a key ${key}' )
440
+ .&End
448
441
449
- Result := LResult.OK;
442
+ .Value
443
+ .Trim
444
+ .&Not .IsEmpty.WithMessage(' O ${key} deve ser informado!' )
445
+ .IsNumeric.WithMessage(' O ${key} não é um valor inválido!' )
446
+ .IsGreaterThan(-1 ).WithMessage(' Informe um valor maior que Zero!' )
447
+ .&End
448
+ .&End
450
449
451
- if not Result then
452
- AMessage := LResult.Informations.GetItem(0 ).Messages;
453
- end )
454
- .&End
450
+ .Validate(' quantity' )
451
+ .Key
452
+ .IsRequired.WithMessage(' Informe a key ${key}' )
455
453
.&End
454
+
455
+ .Value
456
+ .Trim
457
+ .&Not .IsEmpty.WithMessage(' O ${key} deve ser informado!' )
458
+ .IsNumeric.WithMessage(' O ${key} não é um valor inválido!' )
459
+ .&End
460
+ .&End
456
461
;
457
462
458
463
LResult := LJSONResult.Check;
@@ -462,8 +467,8 @@ function TForm2.ValidationTab2: IDataValidatorJSONResult;
462
467
if not Result then
463
468
AMessage := LResult.Informations.GetItem(0 ).Messages;
464
469
end )
470
+ .&End
465
471
.&End
466
- .&End
467
472
end ;
468
473
469
474
procedure TForm2.FormCreate (Sender: TObject);
0 commit comments