Validation of dialog list?

Hi!

On one of my forms I have a dialog list from where the user can choose which customer they would like to use, this field has to be mandatory! Can someone help me with how I should

write the code for this, mine does not work :0(

This is my code:

¨

triggerBeforeUnload = false;

f = document.forms[0];



Customer = f.CustomerID;

  if (Customer.options[selectedIndex].value == '') {

     alert("You have to choose Customer!");

     Customer.focus();

     return false;

  }

Thank you!

//Sandra

Subject: Validation of dialog list?

Use this -

triggerBeforeUnload = false;

f = document.forms[0];

Customer = f.CustomerID;

if (Customer(Customer.selectedIndex).text == “”)

{

alert(“You have to choose Customer!”);

Customer.focus();

return false

}

–Phani

Subject: RE: Validation of dialog list?

Hi Phani!

Thank you, but I tried your suggestion & received an error message that says that “Customer is not a function”, do you know what could be wrong?

My code now looks like this:

function validateForm()

{

triggerBeforeUnload = false;

f = document.forms[0];

Customer = f.CustomerID;

if ( Customer( Customer.selectedIndex).text == “”)

{

alert(“You have to choose a Customer!”);

Customer.focus();

return false;

}

}

Thanks!

/Sandra

Subject: RE: Validation of dialog list?

Try this -

function validateForm()

{

triggerBeforeUnload = false;

f = document.forms[0];

if (f.CustomerId(f.CustomerId.selectedIndex).text == “”)

{

alert(“You have to choose a Customer!”);

f.CustomerId.focus();

return false;

}

}

–Phani

Subject: RE: Validation of dialog list?

Hi again!

The code generates the same error message as before… Can it have something to do how I programme the dialog list? I use “Use view dialog for choises” …

//Sandra

Subject: RE: Validation of dialog list?

I dont know what is the exact problem. Here is what I wanted to let you know -

Copy the code to notepad and saveas .html file. Then test the changes.

Alter your code as per this if anything is missing.

–Phani

Subject: RE: Validation of dialog list?

Hi again!

It works when I test it on a html page as you suggested but not in domino designer… Maybe I put the code in the wrong place? I have placed my code in JS Header on my form. I have other fields that are just regular text fields that works just fine with that kind of validation but when it comes to the dialog box it just does not work…

The code for validating my text fields looks like this:

Adress = f.CustomerAddress;

if (Adress.value == ‘’)

{

alert(“You have to fill out customer address!”);

Adress.focus();

return false;

}

And that works just fine…

I dont know what I am doing wrong :0(

Thanks!

//Sandra

Subject: Validation of dialog list?

I just did this today. I have a dialog list and I want to be sure something is selected when the user clicks the “OK” button.

The function is from Breaking Par (http://www.breakingpar.com/bkp/home.nsf/Category!OpenNavigator&87256B280015193F872570A1005B2D33)

I think you could put the OnClick code in other events, but I’ve not tried that.

Brian

JSHeader:

function getFieldValue(field)

{

switch(field.type)

{

  case "text" :

  case "textarea" :

  case "password" :

  case "hidden" :

     return field.value;



  case "select-one" :

     var i = field.selectedIndex;

     if (i == -1)   return "";

     else   return (field.options[i].value == "") ? field.options[i].text : field.options[i].value;



  case "select-multiple" :

     var allChecked = new Array();

     for(i = 0; i < field.options.length; i++)

        if(field.options[i].selected)

           allChecked[allChecked.length] = (field.options[i].value == "") ? field.options[i].text : field.options[i].value;

     return allChecked;



  case "button" :

  case "reset" :

  case "submit" :

     return "";



  case "radio" :

  case "checkbox" :

     if (field.checked) { return field.value; } else { return ""; }

  default :

     if(field[0].type == "radio")

     {

        for (i = 0; i < field.length; i++)

           if (field[i].checked)

              return field[i].value;



        return "";

     }

     else if(field[0].type == "checkbox")

     {

        var allChecked = new Array();

        for(i = 0; i < field.length; i++)

           if(field[i].checked)

              allChecked[allChecked.length] = field[i].value;



        return allChecked;

     }

     else

        var str = "";

        for (x in field) { str += x + "\n"; }

        alert("I couldn't figure out what type this field is...\n\n" + field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length);

     break;

}

return “”;

}

“OK” OnClick:

var cov = getFieldValue(document.forms[0].Value);

//the field is called “Value”, it’s a copy from something it’s a little confusing, but I’m not changing just no

{

	if (cov == "") {

	alert("Please select a tire")

	return false

	}

	window.returnValue = document.forms[0].Value.options[document.forms[0].Value.selectedIndex].text;

	self.close()

	return true		

	}