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

javascript for blank field validation on repeating subforms

Avatar

Level 4

Hello All!

I have a form with repeating subforms.  You click a button and a second(or third)instance of a subform is generated.

I need to create javascript on a print button that verifies certain fields on each subform is filled in (name address, etc)

I found this doc Loop Through Subform Instances  that shows me how to loop thorough the subform and I can make it work for 1 field, but i have more than one field to validate.


Any idea how to write the javascript that can run through multiple fields on multiple subforms?

Thanks in advance!!!

Jodi

1 Accepted Solution

Avatar

Correct answer by
Level 4

I used this code

expenseReport.#subform[0].validate2::click – (JavaScript, client) 
var vItems = expenses.expense.all; 
for(i=0; i<vItems.length; i++) 

    if (vItems.item(i).description.rawValue == null) 
    { 
        xfa.host.messageBox("Missing description field"); 
        break; 
    } 
}

I had to put the vItems.item(i) for each of the fields.  when I did that it worked!

View solution in original post

3 Replies

Avatar

Level 7

What about just repeating the logic code for the next field? When run, after the first field is verified, the script will just keep running to the next logic code.

You could just use the OR operator to test mulitple fields so it is like 'if this or this or this is null, then do something'

Avatar

Correct answer by
Level 4

I used this code

expenseReport.#subform[0].validate2::click – (JavaScript, client) 
var vItems = expenses.expense.all; 
for(i=0; i<vItems.length; i++) 

    if (vItems.item(i).description.rawValue == null) 
    { 
        xfa.host.messageBox("Missing description field"); 
        break; 
    } 
}

I had to put the vItems.item(i) for each of the fields.  when I did that it worked!

Avatar

Level 7

Thats great. I am going to save that code, i might be able to put it to use.