Hello 

 

I want to set up a validator in the field when the length is greater than 10 characters, it does not allow saving that record. To achieve this I am basing myself on the following example: https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platfor…

Placing it in the following way but it does not work correctly.

 

validators: /**SCHEMA_VALIDATORS*/{
          /* Implement a custom validator type. */
    "usr.ValidateFieldValue": {
        /* Business logic of the validator. */
        "validator": function (config) {
            return function (control) {
                return control.MaxLength !== config.invalidLength ? null: {
                    "usr.ValidateFieldValue": { message: config.message }
                };
            };
        },
        /* Validator parameters. */
        "params": [
            {
                "name": "invalidLength"
            },
            {
                "name": "message"
            }
        ],
        "async": false
    }
}/**SCHEMA_VALIDATORS*/
 
 
 

 

/**SCHEMA_VIEW_CONFIG_DIFF*/,
		viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[
			{
				"operation": "merge",
				"path": [
					"attributes"
				],
				"values": {
					"UsrnumerodeserieDS_Name_zb3wye6": {
						"modelConfig": {
							"path": "UsrnumerodeserieDS.Name"
						},
                       /* The property that contains the list of attribute validators. */
                        "validators": {
                            /* Custom validator. */
                            "ValidateFieldValue": {
                                /* Validator type. */
                                "type": "usr.ValidateFieldValue",
                                "params": {
                                    /* The field value that triggers the custom validator. */
                                    "invalidLength": "10",
                                    /* The tooltip that Creatio displays when the field contains the value specified in the “invalidName” property. */
                                    "message": "Invalid name."
                                }
                            }
                        }
					}
				}
			}

 

Also at some point I modify the code and save it but when I re-enter it does not save the changes and removes what I placed

 

Like 0

Like

1 comments

Hello Laura,

The described situation reminds me that you may apply changes to the unauthorized window. If you relogging into the application - you have to close the Code editor page and open it again after each new login, then changes will be applied.

Please try to modify the code according to the given recommendations and reply to my message if the error persists with additional details about the Error you see.

Show all comments

Is it possible to pass attributes from a page into a validator as a parameter for use in its logic? I'm trying to pass the Id of the record into an async validator which should then query the database for the record to check whether it is in a valid state to be saved, but I don't seem to be able to pass the attribute in as a parameter and it isn't available by default in the validator. I've tried the below:

					"LookupAttribute_sttlz00": {
						"modelConfig": {
							"path": "PDS.QualifyStatus"
						},
						"validators": {
							"LeadSoldValidator": {
								"type": "Usr.LeadSoldValidator",
								"params": {
									"leadId": "$Id"
								}
							}
						},
					},

But it just passes in the literal string "$Id" instead of the value of Id. I don't see anything about passing dynamic values into validators in the documentation.

Like 1

Like

3 comments

Hello,
Currently, this task is in the development and now it is impossible to do so. The ability to add dynamic parameters will be available in the future versions.

Dmytro Vovchenko,

Any idea when it's going to be available? I have a couple of custom validations that test for a regEx expression and I'd like to be able to store those regEx expressions as a setting instead of hard coding them in the code.

Thanks,
Jose

Jose Hernandez 

Hello, 
Unfortunately, we cannot say in which version this functionality will be implemented, as our development team is working on tasks according to their priority, which in turn
is determined by the number of requests with this need.

Show all comments

Hi everyone,

 

Have you already succeed in using Freedom UI custom validators, the academy article was not very successful to me.

 

Best regards,

Like 0

Like

6 comments

Hi Jerome,

They are working for me. One thing I did initially was add it to the control in the viewConfigDiff. You're actually supposed to add the validator to the attribute in the viewModelConfig - not to the control in the diff. Once I moved it there it worked. Your column is likely in the viewModelConfig already (if it's been added to the page). Look for it there and just add the validator to that existing attribute in the model.

Ryan

Thanks Ryan,

 

I managed to step into my validator, but there's no way to retrieve some values (since request is not defined).

 

Best regards,

Jerome BERGES,

Hmm. Not sure about that. I've only used validators where I need the control's value only (which is provided in the params passed in). I had assumed you could pass in other values in the validator params, but that doesn't seem to be the case (or at least I can't figure out how that works). Hopefully we'll see more documentation soon.

Ryan

Joaquin Eztala,

 

Currently, the R&D team is working on such task, they plan to create a solution in the next releases. You can try to workaround in this way:
On the field's change add a custom handler, set a flag in it, look at this global flag (atribute's value) in the validator.

Most likely to validate "if end date it's not before the begin date" you can use in handler await request.$context.DateTimeAttribute_nnnn

Where DateTimeAttribute_nnnn:

	"attributes": {				
	"DateTimeAttribute_nnnn": {
		"modelConfig": {
...
"validators": {
			"StartDateIsNotNotLessThanProjectStartDate": {
				"type": "dw.StartDateIsNotNotLessThanProjectStartDate",
				"params": {
					"message": "#ResourceString(StartDateIsNotNotLessThanProjectStartDateMessage)#",
				}
			},
           "StartDateIsNotNotMoreThanProjectDueDate" ...
		}

 

 

 

Anhelina,

 

A quick question if I may, how do you create a global flag in a client module and how do you look at it in a validator function.  Thanks,

 

edit: I used session storage in the end.

Gareth Osler,

By the phrase "global flag" I meant the attribute value.
This method hasn't been tested, and I can't give you a guarantee of stable work. 

We're still waiting for the out-of-the-box realization and will post the article with updates on the Academy.

Show all comments