Jump to:

17452 Posts in 4473 Topics by 1971 members


SilverStripe Forums » Archive » CompositeDateField and Validator

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 1017 Views
  • zyko
    Community Member
    66 Posts

    CompositeDateField and Validator Link to this post

    I need a control to put in someone's birthday.
    It turned out, that all the other controls are not fitting to that scenario.
    So i took CompositeDateField

    But it turned out, that the RequiredFields validator doesn't work if i use this control.

    I made a copy of the code (also needed for 'translation' of year and that things)

    class EventCompositeDateField extends DateField

    and tryed to make a better implementation of

    function jsValidation()

    dateParts = $(fieldName).getElementsByTagName('select');

    doesn't work, because fieldnames are
    fieldName + "[date]";
    and nothing is found using the original javascript code.

    So i made 'three checks, for any part of the field'

    BUT: if i don't use

    before doing a

    no error is shown.
    BUT if i use it, errors are shown 'immediately' and not if someone leaves the fields...

    I think this is a problem, because validator only supports 'one field' things out of the box.
    and here we have three of them...
    but i'm not sure what element to put into the function

    my code looks something like that:

    validateCompositeDateField: function(fieldName) {
           var fln1 = fieldName + "[date]";
             var el1 = _CURRENT_FORM.elements[fln1];
             if(!el1 || !el1.value) return true;

           var fln2 = fieldName + "[month]";
             var el2 = _CURRENT_FORM.elements[fln2];
             if(!el2 || !el2.value) return true;

           var fln3 = fieldName + "[year]";
             var el3 = _CURRENT_FORM.elements[fln3];
             if(!el3 || !el3.value) return true;
           //zyko: Without this line, there's no Error at all...
             if(el1.value == 'NotSet'){
                validationError(el1,"Bitte gib einen gültigen Tag an.","validation");
                return false;
             if(el2.value == 'NotSet'){
                validationError(el2,"Bitte gib ein gültiges Monat an.","validation");
                return false;
             if(el3.value == 'NotSet'){
                validationError(el3,"Bitte gib ein gültiges Jahr an.","validation");
                return false;
             return true;         

    any idea would be cool to hear ;-)

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.