Expand my Community achievements bar.

SOLVED

Validation Button

Avatar

Level 5

There are so many Text field i.e Text field1, Text field2, Text field3, Text field4 ............All fields are required.

If any field empty, alert message show which fields are empty after clicking validation button. (On one pop-up message all empty fields are shown)

Example:

On one pop_up box:

Please specify Text field1, Text field2...... (if Text field1, Text field2 .....are empty)

Is it possible? What is the code for it?

1 Accepted Solution

Avatar

Correct answer by
Level 7

Oops!

I think I see 2 problems with last 6 lines of my script:

///////////////////////////////////////////////////////////////////////////////////////////////////

validationMessage = Substr(validationMessage, 0, VMtrim)

if (validationMessage > "Please complete the following required fields: ") then

     VMtrim = Len(validationMessage - 2)

     validationMessage = Substr(validationMessage, VMtrim, 2)

     xfa.host.messageBox(validationMessage, "Missing Required Fields", 3)

endif

///////////////////////////////////////////////////////////////////////////////////////////////////

Instead, it should be:

///////////////////////////////////////////////////////////////////////////////////////////////////

validationMessage = Substr(validationMessage, 0, VMtrim)

if (validationMessage > "Please complete the following required fields: ") then

     VMtrim = Len(validationMessage) - 2

     validationMessage = Substr(validationMessage, 0, VMtrim)

     xfa.host.messageBox(validationMessage, "Missing Required Fields", 3)

endif

///////////////////////////////////////////////////////////////////////////////////////////////////

Try that and see what you get. AND if it doesn't fix it, it would be helpful to know if you are seeing "Le" or "le" 

Sorry for the errors!

Good luck!

Stephen

View solution in original post

9 Replies

Avatar

Level 7

Hi,

Try the following:

================================================================

ButtonSOM::click - (FormCalc, client)

var validationMessage = "Please complete the following required fields: "

var VMtrim

if (hasValue(TextField1) == 0) then

     validationMessage = Concat(validationMessage, "NameOfField, ")

endif

if (hasValue(TextField2) == 0) then

     validationMessage = Concat(validationMessage, "NameOfField, ")

endif

if (hasValue(TextField3) == 0) then

     validationMessage = Concat(validationMessage, "NameOfField, ")

endif

//etc., etc....

if (validationMessage > "Please complete the following required fields: ") then

     VMtrim = Len(validationMessage - 2)

     validationMessage = Substr(validationMessage, VMtrim, 2)        //trims off the last space and comma

     xfa.host.messageBox(validationMessage, "Missing Required Fields", 3)

endif

=======================================================

That should do the trick. Here are some additional ideas:

1)  You could have each "if(hasValue)then" script use the value of the caption for the NameOfField.

2)  You can get fancier with the messageBox and format it so each failed field appears on a separate line in the messageBox.

3)  You could have each "if(hasValue)then" script highlight the field and then place a script on the field exit event to test for hasValue() and remove the highlighting

4) You can name the fields the same, and their containers the same, construct a loop that tests hasValue() for each one and uses the caption value in constructing the messageBox string.

I likely won't be able to reply for a few days.

Cheers,

Stephen

Avatar

Level 5

Hi Stephen,

Thanks for reply,

I am going to test.

Avatar

Level 5

Nice!

However warming message shows only "le", not show Please complete the following required fields:

What should I do?

Avatar

Correct answer by
Level 7

Oops!

I think I see 2 problems with last 6 lines of my script:

///////////////////////////////////////////////////////////////////////////////////////////////////

validationMessage = Substr(validationMessage, 0, VMtrim)

if (validationMessage > "Please complete the following required fields: ") then

     VMtrim = Len(validationMessage - 2)

     validationMessage = Substr(validationMessage, VMtrim, 2)

     xfa.host.messageBox(validationMessage, "Missing Required Fields", 3)

endif

///////////////////////////////////////////////////////////////////////////////////////////////////

Instead, it should be:

///////////////////////////////////////////////////////////////////////////////////////////////////

validationMessage = Substr(validationMessage, 0, VMtrim)

if (validationMessage > "Please complete the following required fields: ") then

     VMtrim = Len(validationMessage) - 2

     validationMessage = Substr(validationMessage, 0, VMtrim)

     xfa.host.messageBox(validationMessage, "Missing Required Fields", 3)

endif

///////////////////////////////////////////////////////////////////////////////////////////////////

Try that and see what you get. AND if it doesn't fix it, it would be helpful to know if you are seeing "Le" or "le" 

Sorry for the errors!

Good luck!

Stephen

Avatar

Level 5

Great!!!!!

I am so much happy.

Another one:

If I want all caption of which field is empty will be new line, what I should do. Now they are one line with comma.

Avatar

Level 7

Hi,

I'm sorry,

I'm really tired right now and not thinking clearly. I've been traveling back and forth to 3-day conference. I will get some rest and post something tomorrow.

Stephen

Avatar

Level 5

Sure.

I am grateful to you. You have helped me today though you are tired.Thanks again.

Have a good sleep!

Best regards

Mehedee

Avatar

Level 7

Hi,

There are a number of ways to produce the message--normally, I would choose a loop and loop through the fields until I find an empty one and stop, highlight the field, setFocus() on the empty field and display the message about that empty field using the value of the empty field caption in the message. Then the user completes the field and presses the button. The process repeats.

When you develop your skills, you can then think about doing the above, if it is the right solution for the problem.

What I can provide you with, is a way to format the messagebox() a little better so that each empty field appears on a different line in the message box:

Modify your script like this:

  • add the Unicode for a Line Feed \u000A
  • remove the commas after each field name
  • remove the script that uses the variable VMtrim to cut off the last comma in the validationMessage

Your script will look something like this:

=========================================================

var validationMessage = "Please complete the following required fields: "

if (hasValue(TextField1) == 0) then

     validationMessage = Concat(validationMessage, "\u000ANameOfField")

endif

if (hasValue(TextField2) == 0) then

     validationMessage = Concat(validationMessage, "\u000ANameOfField")

endif

if (hasValue(TextField3) == 0) then

     validationMessage = Concat(validationMessage, "\u000ANameOfField")

endif

//etc., etc....

xfa.host.messageBox(validationMessage, "Missing Required Fields", 3)

========================================================

Good luck!

Stephen

Avatar

Level 5

Hi,

Thanks a lot. Perfect!!!

It works well.