Form Dilemma

Issues related to forms.
Post Reply
User avatar
gofrank
 
 
Posts: 91
Joined: Sun Dec 30, 2007 2:43 am
Location: Florida, USA

Form Dilemma

Post by gofrank » Thu Nov 02, 2017 11:49 pm

I have a client who has requested a form with multiple combo boxes. For this example, I'll call them combo1 and combo2.

Combo1 has a yes/no selection. If the selection is "Yes", combo2 is disabled as being unnecessary. If combo1 is "No", combo2 is enabled. All this works great with the Conditions in WB12.

However...

Combo2 is a required selection IF it is enabled. Unfortunately, when combo2 is disabled, the validation code insists on requiring a selection (which isn't possible).

Is there a way to a) disable the required property if combo2 is disabled, or b) modify the validation code so that it checks for combo2 being enabled (as well as a selection being made) before displaying the alert requiring a selection?

Something like:

Code: Select all

if (theForm.combo2.selectedIndex < 0) && (!theForm.combo2.disabled)
   {
      alert("Please indicate a selection.");
      theForm.combo2.focus();
      return false;
   }
(Pardon my rough code example. My Javascript is very rusty!)
Billing clients for your freelance work? Try Minute-2-Minute, the project management, timing, and billing system. Perfect for web developers who charge by the hour. FREE 45-day trial.

User avatar
[RZ]
 
 
Posts: 2442
Joined: Tue Nov 04, 2008 12:08 pm

Re: Form Dilemma

Post by [RZ] » Fri Nov 03, 2017 5:31 am

are you sure you need 2 combos?
maybe you need just one checkbox (to make the combo visible or not via events) and the combo itself to get the relevant value
or
perhaps this may help you? viewtopic.php?f=53&t=77382

User avatar
Pablo
 
Posts: 19667
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Form Dilemma

Post by Pablo » Fri Nov 03, 2017 7:04 am

Is there a way to a) disable the required property if combo2 is disabled
There is no standard solution for this.
So you will need to disable the built-in validation and implement your own code.
or check out rz's solution.

User avatar
gofrank
 
 
Posts: 91
Joined: Sun Dec 30, 2007 2:43 am
Location: Florida, USA

Re: Form Dilemma

Post by gofrank » Fri Nov 03, 2017 12:31 pm

maybe you need just one checkbox (to make the combo visible or not via events)
The visibility is not the problem. It's the validation. Regardless of the control's visibility or being disabled, the validation is still in effect. Unfortunately, my client is requiring both responses to be included on the form.

Nonetheless, thanks for the feedback. I'll explore Pablo's suggestion of a separate validation process.
Billing clients for your freelance work? Try Minute-2-Minute, the project management, timing, and billing system. Perfect for web developers who charge by the hour. FREE 45-day trial.

User avatar
gofrank
 
 
Posts: 91
Joined: Sun Dec 30, 2007 2:43 am
Location: Florida, USA

Re: Form Dilemma

Post by gofrank » Fri Nov 03, 2017 4:31 pm

Okay, here's a solution that works (for the benefit of anyone else who runs into this sort of problem). Thanks to WB's flexibility, it worked out to be fairly simple.

First, I removed all the validation from combo2 on the form.

Then, in the form's submit button HTML, I added this code to the "Inside Tag" tab:

Code: Select all

onclick="return ValidateAltCombo();"
Finally, I went to the Page HTML section, and added this code to the "Before </body>" tab:

Code: Select all

<script type="text/javascript">
function ValidateAltCombo()
{
   var c = document.getElementById("combo2");
   if ((c.selectedIndex < 1) && (!c.disabled))
   {
      alert("Please make a selection in combo2.");
      c.focus();
      return false;
   }
}
</script>
The combo box .selectedIndex is tested for less than 1 as the first selection in the combo is not allowed (the index of the first selection is zero). The alert is displayed only if no selection has been made in combo2 AND combo2 is not disabled.
Billing clients for your freelance work? Try Minute-2-Minute, the project management, timing, and billing system. Perfect for web developers who charge by the hour. FREE 45-day trial.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests