Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

DropDownList Validation

Avatar

Level 4

Hello folks,

If I have the following dropdown list items:

  • "SELECT"
  • "Male"
  • "Female"

And I want to enforce the user to select one of them except the "SELECT" item, how can I do that?

I've chekced out the User Entered - Requiered feature but it didn't help me at all - always paint my DDL border in red, when any item was selected.

Thank you,

Yair

11 Replies

Avatar

Level 4

Hi

My guess is that you want the box to display 'select' in order for users to know to select from the box.

Therefore in the preOpen event enter something like

if (this.rawValue == null) {

this.rawValue = "Select";

}

Remove the 'select' drop down that you originally entered to avoid confusion. Make sure that the default in the Value tab is also set to 'none'.

Hope this helps.

Avatar

Level 4

No, I want to tell the user to select a gender if he left the drop down list with the SELECT selected.

Yair

Avatar

Level 4

Where on the form do you want this validation? Is it on a separate button?

Avatar

Level 4

I want to treat the SELECT item as not selected and to tell the user that he need to select a gender.

The validation should be on the Form Submit event

Message was edited by: Yair-Nevet

Avatar

Level 10

Hi, I don't believe that you need a validation script at all. Delete the "Select" from the items in the Object > Field palette. Then in Patterns dialog set up a null pattern with "Select". This way when the dropdown is null it will display "Select", no script required. Niall

Avatar

Level 4

How do you want to validate that box then - when they click a button / send

email/when they click in the drop down?

The easy thing you could do is to automatically set the default to either a

male or female.

Avatar

Level 4

Hi Niall,

All what I want to do is to check if the user select a gender, if he didn't, I want to tell him to select one.

What should I do?

Thank you,

Yair

Avatar

Level 4

Good morning Niall,

I'm using the script that you sent me yesterday.

It works O.K except the fact that if the user didn't select a gender - no error or red border comes up on the form submit event.

Maybe the resolveNode isn't work?

how should I find my object(Gender dropdownlist) hierarchy path?

How can I get some indication from the resolveNode function that the node was find?

Thank you very much and have a good day,

Yair

Avatar

Level 10

Hi Yair,

The hierarchy is a palette that you use a lot. Also it is important that you name pages and objects as you create them, as it makes it much easier to reference in script. This is how you build up a full reference:

2010-12-08_08-41-04.png

xfa.form.form1.page1.gender

  • 'xfa' is the top object in the hierarchy. You don't see it in the hierarchy palette, but it is there.
  • 'form' refers to Form DOM (Document Object Model), which is a child object of XFA (one of many). Again you don't see it in the hierarchy.
  • 'form1' is the top object in the hierarchy. This is the default name that LC Designer gives it, but you can change it if you want/need to.
  • 'page1' is the name that I have given to the first page. If you have not named the page, then it will make it more difficult to reference objects contained inside the page.
  • 'gender' is the name of the dropdown object.

So if you amend the script to reflect your hierarchy then it should work. For example if the dropdown is in other subforms, you would need to include these in the reference, in the correct order.

When debugging a form, it is useful to open the JavaScript Console (press Control+J). If there are errors in the script as you interact with the form, they should show up in the console.

Hope that helps,

Niall

Assure Dynamics

Avatar

Level 4

Thank you very much Niall,

Your help assited me well.

There is what to study of you!