Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

map and Invoke client libs to form objects

Avatar

Level 1

Hi,

I am trying to achieve below use-case:

1. create custom client-libs for validating field objects. Main events are validate, value commit and click.

2. I want to invoke functions written in client libs to validate the fields without writing function call or use rule-editor at all. May be via events.

3. Also, we don't want to hardcode object name in client Libs and it should apply at whole form with field type. So that we can re-use it on other forms.

 

I have created client libs which has a function test(){ if(val>10) return true;} else false; 

How can I map this field to form object without field name and without rule editor and bind it to numeric box validate event. 

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Hi @Shiva27 ,

Here you have multiple scenarios. Let's see the recommended approach to apply validation/rules on forms.
1. Do not use client libs, just write validation in rule/code editor.
2. Use client libs-> map it to form container-> call the function written in libs via visual/code editor.
3. You want to make re-usable client libs then as well approach 2 will work fine. But you have to invoke the method from the form on certain events.

Coming to the question where you want to invoke client libs without even calling it from forms then you will not be leveraging any capability of the adaptive form. Which is not an ideal scenario.

You can create re-usable client libs and have functions that need to be called by another form but you need to invoke the method somehow. Adaptive form Validate event gives you the way to leverage error and success widget and if you do not use forms capability it will just be vanilla js.

Suggestion-> Write client libs with functions-> invoke function from form based on the logic.

Mayank_Gandhi_0-1628081486814.png

 

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

Hi @Shiva27 ,

Here you have multiple scenarios. Let's see the recommended approach to apply validation/rules on forms.
1. Do not use client libs, just write validation in rule/code editor.
2. Use client libs-> map it to form container-> call the function written in libs via visual/code editor.
3. You want to make re-usable client libs then as well approach 2 will work fine. But you have to invoke the method from the form on certain events.

Coming to the question where you want to invoke client libs without even calling it from forms then you will not be leveraging any capability of the adaptive form. Which is not an ideal scenario.

You can create re-usable client libs and have functions that need to be called by another form but you need to invoke the method somehow. Adaptive form Validate event gives you the way to leverage error and success widget and if you do not use forms capability it will just be vanilla js.

Suggestion-> Write client libs with functions-> invoke function from form based on the logic.

Mayank_Gandhi_0-1628081486814.png