custom validation for radio buttons dosn't work

lupusdesign 18 Oct, 2013
Hello,

i have a custom form with custom validation for some fields. It work's fine. But on radio buttons the custom validation dosn't work. I add a custom validation in the html code, but only the "required" validation will be used!
I used the attribute class="validate['%checkAbholung']" to call my own js function, the result of the validation is the same like class="validate['%required']" and my function is not called.

The form is on my local machine, but here is the code of the radio group:

<fieldset id="fabholung_kr">
  <legend id="labholung_kr">Sie möchten Ihre Bestellung</legend>
  <input id="abholung_kr" name="abholung" type="radio" value="Abholung" class="validate['%checkAbholung']">
  <label for="abholung_kr"> abholen in unserer Filliale oder</label><br>
  <input id="lieferung_kr" name="abholung" type="radio" value="Lieferung" class="validate['%checkAbholung']">
  <label for="lieferung_kr"> liefern lassen an die angegebene Adresse.<span id="liefergebiet"> (nur PLZ-Gebiet 00000)</span></label>
</fieldset>


What am I doing wrong? Can you help me?
GreyHead 18 Oct, 2013
Hi lupusdesign,

What is the custom function code?

I've never tried a custom validation on a radio button but would expect that it should work OK.

Bob
lupusdesign 18 Oct, 2013
Hi Bob,

i think the problem is, that the custom function is never called. I checked it with a breakpoint in firebug. Alle other custom functions will work fine.
The code of the function:

function checkAbholung(el) {
    var abholung = document.getElementById('abholung_kr');
    var lieferung = document.getElementById('lieferung_kr');
    
    if (!abholung.checked && !lieferung.checked) {
        el.errors.push('Bitte wählen Sie aus, ob Sie Lieferung oder Abholung wünschen.');
        return false;
    }
    
    var plz  = document.getElementById('plz_kr');
    if (lieferung.checked && trim(plz.value) != '01234') {
        el.errors.push('Lieferung ist nur innerhalb der PLZ 01234 möglich. <br> Bitte wählen Sie Abholung.');
        return false;
    }
    
    return true;
}
This topic is locked and no more replies can be posted.