In our applications we always need to add codes to validate some field in the form.


RadCORE brings an attribute to reduce this encoding.


Let's take the example of user registration. Here, I added 3 validations:


- LOGIN

- EMAIL

- NEW PASSWORD


Observe the "HINT" property of each component mentioned above (respectively):


[[valid:blank]] : Indicates to RadCORE that this field CANNOT BE BLANK.

[[valid:email]] : Validate an EMAIL.

[[valid:pass]]  : Validate a PASSWORD (please note in "mkm_validate" the current validation criteria).

[[valid:date]]  : Validate a DATE.

[[valid:cpf]]   : Validate a CPF.

[[valid:cnpj]]  : Validate a CNPJ.

[[valid:min-99]]: Validate the minimum input of "99" characters.

[[valid:max-99]]: Validate the maximum input of "99" characters.


Registration Validation


[[valid:not-exists]]: Validate if the field content in the current "uniDBEdit" has already been registered to avoid duplication.


variations:


valid:not-exists<str> where:DEL<>'S' : Validate if the field content in the current "uniDBEdit" has already been registered (its content being STRING ) to avoid duplication and only if the "DEL" field is different of 'S'


valid:blank=Loja ifvisible:rcBlock40 : Validate if the content of the "Loja" field is not empty and only if the "rcBlock40" component is visible.


Note: there is also the "ifenabled" parameter.



Other possible variations that will further reduce the coding:


[[valid:=nn or >nn<int>]]

[[valid:>dd/mm/yyyy]]

[[valid:>=nn and <=nn]]

[[valid:>nn.nn and <=nn]]


Note: The above models can be tested in "frmCadCLIENTES" present in RC BRASIL / GLOBAL projects and for Brazilians, there is an example of multiple validation of CPF or CNPJ in the same field.





It is also possible to carry out the validation only if the field is filled in, that is, it is allowed to be left blank.


[[valid:email notblank]] 



It is also possible to add a string that represents the name of the field that is blank to be displayed to the user.


[[valid:blank=Email]] 



It is also possible to validate a field based on the content of another:


      "ifnotempty:aaaaa" e "if>0:aaaaa" 


      Where "aaaaa" is the name of an editing component.


      There are 2 fields and you only want the second field to be validated if the first one has content greater than zero or the first one is not empty:



      [[valid:blank=Email if>0:edInvoiceNumber]]

      [[valid:blank=Email ifnotempty:edInvoiceNumber"  



Note: See some examples on "frmDEMO_FORM"



Validation Manual Cleaning


In the example above, in the "Remove Mask" button, you can see how to clear the validation.


rc_ClearValidation(self);



Validating only the components within a "Parent" 


It is possible to pass a parameter indicating to be validated only the components that are within a particular "Parent" (UnicontainerPanel, Uniscrollbox ...)


   if not rc_formvalidate (self, rcblock46) then

   begin

      Abort;

   End;


In the example above, only components within "RCBlock46" will be validated.



Conditional Validation


In the customer register we have an example of Conditional Validation in the "edCnpjCpf" field:


[[valid:cpfcnpj &edTipoPessoa="F J"]] : Criticize a valid CPF / CNPJ according to the content of "edTipoPessoa", that is,

    if it is an individual, it will criticize CPF, if not, CNPJ.


> CPF and CNPJ are types of documents used in Brazil to identify a person or a company, respectively.


> In the "mkm_validate.pas" unit you can add new validations in addition to the existing ones.


When clicking on the "btnSaveReg" Button, the fields validation function will be executed in "frmBaseCRUD":



Remember: 

By default, the "rc_Validate" function call is only in "frmBaseCRUD". 

If you need to validate other operations in other forms which don't inherit from "frmBaseCRUD" you just copy it to where you want.


NOTE: There needs to be a "Unisweetalert" component in its source form/frame with the name "RCSweetalert" so that the validation and focus control messages work.

Created with the Personal Edition of HelpNDoc: Full-featured Help generator