Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to make a submit button that skips validation?

Avatar

Level 2

In a dynamic form with custom validation I need to have two different submit buttons. One to submit form data as is and and other to validate the data first then submit.

How can I create a submit button that skips validation?

Thx

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

The allChileElements will give you everything under that node (fields, subforms, draws, etc....) Some of those objects do not have a validate property. Thats why there is a further qualification where we are grabbing objects with a specific className of subform or field. If it is a subform then we need to dig deeper into that structure, if it is a field then we can set the validation.

Make sense?

paul

View solution in original post

9 Replies

Avatar

Former Community Member

You can''t force the skipping of the validations. You woudl have to create a different means of performing validations by not using the validate event but by calling your validations from your own program when you hit th enon validate submit button.

Make sense?

Paul

Avatar

Level 2

Thx for the reply Paul. I am not calling any validate event of any field. They are being called automatically when the submit button is clicked.

Some of my fields have some function calls under their validate event.  I need to find a way to either not call does funtions when button A is pressed or may be set a global variable to true as soon as the button is pressed? then check for that at validate event of my fields to see if validation needs to be performed.

What do you think of that?

Where is the best place to make declare this global variable and at which event of Button A should I set it to true?

Avatar

Former Community Member

That woudl work fine .....you can use a hidden field to hold your status variable and I woudl use the click event of the button to execute your code. If you have any code on validate events it will be called automatically when you do a regular submit. You would put all of that validate code into a single script or func

tion and call it from the button click event.

Hope that helps

Paul

Avatar

Level 2

I tried that. I can skip my own validation functions but I still need to skip "nullTest" validation too.

Here is an XML excerpt from one of the fields:

        <validate nullTest="error">

                     <message>

                        <text name="scriptTest">Field X is required</text>

                        <text name="formatTest">- Form Details-</text>

                     </message>


                     <script contentType="application/x-javascript">

                         //run my validation function here if skipValidationFlag is off

                    </script>

     </validate>

I figured I can change nullTest to "disabled" using javascript. So when my submit button is pressed I have to do this for every single field : !!!


field.validate.nullTest = "disabled";

then set them back to "error" so the normal submit button with validation would work.

So now my question is, how can I loop over all fields that have nullTest="error" ? can I keep track of them in an array?

Avatar

Former Community Member

I have a sample that shows how to get back each field on a form ....I use it to lock each field but you can do whatever you want with it.

The code is in a function on this form and the function wil lock all fields in a subform that is passed to the function.

Paul

Avatar

Level 2

The function is very helpful, thx.

I just have an issue accessing validate object under the field elements. I can lock all fields using you LockAllFields() I added the following into the loop script:

allChildElements.item(j).validate.nullTest = "disabled";

In Acrobat's debuger I get an error saying "allChildElements.item(j).validate is undefined". Evey Node must have a validate object as far as I know. Aren't allChildElements.item(j) nodes?

Avatar

Correct answer by
Former Community Member

The allChileElements will give you everything under that node (fields, subforms, draws, etc....) Some of those objects do not have a validate property. Thats why there is a further qualification where we are grabbing objects with a specific className of subform or field. If it is a subform then we need to dig deeper into that structure, if it is a field then we can set the validation.

Make sense?

paul

Avatar

Level 2

I discovered it (in a hardway). I ended up using try { ...}catch(e){} 

Now I can disable nulltest for most fields. I say most fields because there could be multiple instances of some fields (in dynamicly generated fields) so I may have 3 previousJobTitle fields. User can add more as needed. Our function does not seem to capture those repatable fields.

looking into the reference I am trying to do something like the following the function reaches a subform:

currentSubformFieldsNodes = currentElement.resolveNodes("#fields[*]");

Avatar

Level 2

Thx Pual, I solved it using your function.

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