Dropdown selection makes field required

mackirony 23 Aug, 2010
Hi, it's been a while but I stumbeled on a small problem again.

First off al, I'm using 3.1 RC5.5 on Joomla 1.5.20

I have a dropdown menu whitch shows a textfield on one option and hides it on athy other option. I've been trying to have this text-field required only when the selection option (showing the txtfield) is selected.

Simplified form code:
<label class="cf_label" style="display: block; width: 150px;">Category</label>
<select name="category" title="" size="1" id="category" firstoption="1" firstoptiontext="Choose Option" class="cf_inputbox validate-selection">
	<option value="">Choose Option</option>
	<option value="DJ">DJ</option>
	<option value="Producer">Producer</option>
	<option value="Label">Label</option>
	<option value="Organiser">Organiser</option>
	<option value="Deco crew">Deco crew</option>
	<option value="VJ">VJ</option>
	<option value="Performer/Stage act">Performer/Stage act</option>
	<option value="Other">Other-Request a new category</option>
</select>

<div id="catrequest">
<label class="cf_label" style="width: 300px;">New category</label>
<input class="cf_inputbox required" maxlength="150" size="30" title="" id="requestcat" name="requestcat" type="text" />
</div>

<input value="Send" name="button" type="submit" />


In the Javascript box. I have commented out the parts that will show and hide the div conatining the text field.
window.addEvent('domready', function() {
									 
// set fields to not display									 
//        $('catrequest').setStyle('display', 'none');
			$('requestcat').removeClass('required');
		
  $('category').addEvent('change', function(event) {
    var e = new Event(event);
    if (e.target.value == 'Other') {
//      $('catrequest').setStyle('display', 'block');
			$('requestcat').addClass('required');
    } else {
//    $('catrequest').setStyle('display', 'none');
			$('requestcat').removeClass('required');
    }
  });
});


If I checkt this in firebug it seems to work. "required" is removed from the fields class on page load and any non "other" selection option and added on the selection option with the "other" value. But still the field seems to be required all the time.

Ive been trying to figure out how to fix this but couldn't find any working solution to this issue. I came up with this code by addapting the code from the post I made about radio buttons making field upload required. I tried everithing within my knowledge and I failed so please help ;-)
mackirony 27 Aug, 2010
I'm really at a dead end here. What ever I try I feel this should work.
Max_admin 28 Aug, 2010
Hi mackirony,

I think the "Live validation" library used in validation requires that you "enable/disable" the validation when you want to change the validation dynamically, so changing the class only may not enough.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 28 Aug, 2010
Hi mackirony,

I think that Max is right here. ChronoForms uses the classes to apply LiveValidations to each of the inputs when the page is loaded. After that the class no longer makes any difference :-( Instead you need to enable and disable the LiveValidations. unforunately I've not yet succeeded in disabling one a LiveValidation set by ChronoForms . . . I'm sure this should be possible but my JavaScript just isn't up to it.

It might be possible to work around this by using custom Validations and applying them from a script in the page (i.e. not by using the validation classes). Then you should be able to enable or disable them as you need.

Bob
Max_admin 28 Aug, 2010
Hi Mack,

I think so, so you have to use the same code as there, it's just as Bob explained, you can enable/disable the validation only if it's set by your own code, not by the Chrono Auto classes. so make sure that your text field doesn't have any validations set through the wizard or the "validation" tab.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
mackirony 28 Aug, 2010
Yes I see the difference now. However I changed my mind about the structure of my form. Because eventually I will be needing different fields required for different selection options. I descided to go back to radio buttons and adapt the javascript mentioned in the other thread for that.

I will come back to this thread when I need this again. I'm sure I will some day😉

Thanks guys!
This topic is locked and no more replies can be posted.