Expand my Community achievements bar.

SOLVED

Using validation pattern to control visibility

Avatar

Level 2

Hi all, hoping you can help me again with a query. I'm using LiveCycle Designer ES2.

I have a text field on my form - let's say Account Number -  that has a validation pattern of text{AA999}|text{99999}  i.e it must be a 5 character string, either two letters and three numbers or 5 numbers. This is set in the Validation Pattern GUI, not in script.

What I'd like to do is control the visibility of another field - let's say Account Name - based on whether Account Number validates correctly or not. I know how to write the script to control the visibility, but not sure what test to do for it. Something like...

if (<<how do I write the test to see if it validated correctly?>> == true)

{

AccountName.visibility = "visible";

}

else

{

AccountName.visibility = "hidden";

}

Can anyone guide me as to how to do this?

Thanks

Matt

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

if you call the validate method of the object it will return a true or false based on whether teh validation passed or failed.

So your code would look something like this:

if (fieldName.execValidate() == true)

{

AccountName.visibility = "visible";

}

else

{

AccountName.visibility = "hidden";

}

View solution in original post

4 Replies

Avatar

Level 10

Using Regular Expressions is the best approach for this requirement. But you need to write a few lines of code in javascript.

Nith

Avatar

Correct answer by
Former Community Member

if you call the validate method of the object it will return a true or false based on whether teh validation passed or failed.

So your code would look something like this:

if (fieldName.execValidate() == true)

{

AccountName.visibility = "visible";

}

else

{

AccountName.visibility = "hidden";

}

Avatar

Level 10

Interesting and pretty simple solution !

Thanks Paul.

Avatar

Level 2

Hi both,

Thanks for your responses - Nith yes I did think about using regular expressions but I wasn't sure of the syntax needed to check for my requirements, hence why I used the pattern editor.

Paul - thanks for your help - this works perfectly.

Matt

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] ----