Expand my Community achievements bar.

SOLVED

hooking up custom validation

Avatar

Former Community Member

Hi all.

AEM (6.2) Forms provides validation facilities for entry fields (email, telephone) for example. We'd like to add new functions that we can share, for more than just simple patterns. In the rules editor (visual editor) there is function list you can use. We'd like to add to that.

We tried creating this:

/**
 *Validate pattern
  *@param {string} pattern - the pattern to use
 */
 function ValidatePattern(pattern) {

    console.log('hello');
     return (this.value && this.value.match(pattern) == null) ? false : true;
 }
 

..Just to see if "ValidatePattern" would show up in the VisualEditor/FunctionsList. It *does*, but it's not called.

Suggestions?

-Joel

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

We solved this ourselves.

Basically you need to:

1. Create js specifically for validation. Similar to:

    var saveAndAddClickHandler = function(param) {
        //do something

 }

 

2. Now "saveAndClickHandler" is available as a drag and drop function for your button function list.

Joel

View solution in original post

2 Replies

Avatar

Former Community Member

Further to this...AEM uses the JCR property "validateExp" to do validation.

guideRuntime.js:25733:

            if (validFlag && this.validateExp ) {
  >>              validFlag = this.executeExpression("validateExp");

guideRuntime.js:25149:

        _expressionHandler: function (expressionName) {
            var expFn, returnValue;
            if (this._compiledExpressions[expressionName]) {
                expFn = this._compiledExpressions[expressionName];
                try {
>>                     returnValue = expFn.apply(this);

We have the option to override guideRuntime.js (I think) to check our own JCR property for a function we implement, but we'd rather not override core stuff.

Is there a more standard way to do this to build our own library of functions to validate?

Avatar

Correct answer by
Former Community Member

We solved this ourselves.

Basically you need to:

1. Create js specifically for validation. Similar to:

    var saveAndAddClickHandler = function(param) {
        //do something

 }

 

2. Now "saveAndClickHandler" is available as a drag and drop function for your button function list.

Joel

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----