Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="row" id="EventDate">
    <label for="Date">Event date <em class="asterisk"><span>*</span></em></label>
    <div class="selectmenu xsmall-type1 inputDOB">
        <select id="Date" name="EventDateDay" aria-required="true" class="js-selectmenu" data-val-required="Please tell us your event date" data-val="true">
          <option value="">DD</option>
          <option value="01">01</option>
          <option value="02">02</option>
          <option value="03">03</option>
          <option value="04">04</option>
          <option value="05">05</option>
          <option value="06">06</option>
          <option value="07">07</option>
          <option value="08">08</option>
          <option value="09">09</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
          <option value="24">24</option>
          <option value="25">25</option>
          <option value="26">26</option>
          <option value="27">27</option>
          <option value="28">28</option>
          <option value="29">29</option>
          <option value="30">30</option>
          <option value="31">31</option>
        </select>
    </div>

    <div class="selectmenu xsmall-type1 inputDOB">
        <select id="Month" name="EventDateMonth" aria-required="true" class="js-selectmenu" data-val-required="Please tell us your full date of birth" data-val="true">
          <option value="">MM</option>
          <option value="01">01</option>
          <option value="02">02</option>
          <option value="03">03</option>
          <option value="04">04</option>
          <option value="05">05</option>
          <option value="06">06</option>
          <option value="07">07</option>
          <option value="08">08</option>
          <option value="09">09</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
        </select>
    </div>


    <input id="EventYear" 
      type="text" 
      name="EventYear" 
      class="form_input--inline inputDOB" 
      aria-required="true" 
      placeholder="YYYY" 
      data-val-required="Please tell us your full date of birth"
      data-val-length-max="4" data-val-regex="Event Date is invalid."
      data-val-length="Event Date must be less than 4 characters."
      data-val-daymonthyear="{0} is required." 
      data-val-regex-pattern="^[0-9]*$"  
      maxlength="4" 
      data-val="true" />
    <div class="error-message" role="alert">
      <div class="error-text">
        <p><span class="field-validation-valid" data-valmsg-for="DOB" data-valmsg-replace="true">Please tell us your event date</span></p>
        <img src="http://res.cloudinary.com/df821af5o/image/upload/v1499521750/mcr-error-bg_wfz31v.png" alt="">
      </div>
    </div>
    <div class="inline-error-message">
        <div class="error-text">
            <p></p>
            
        </div>
    </div>
</div>
<div class="row" id="EventDateEnd">
    <label for="DateEnd">Event End Date (optional) </label>
    <div class="selectmenu xsmall-type1 inputDOB">
        <select id="DateEnd" name="EventFullDateEnd" class="js-selectmenu" data-val="true">
          <option value="">DD</option>
          <option value="01">01</option>
          <option value="02">02</option>
          <option value="03">03</option>
          <option value="04">04</option>
          <option value="05">05</option>
          <option value="06">06</option>
          <option value="07">07</option>
          <option value="08">08</option>
          <option value="09">09</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
          <option value="24">24</option>
          <option value="25">25</option>
          <option value="26">26</option>
          <option value="27">27</option>
          <option value="28">28</option>
          <option value="29">29</option>
          <option value="30">30</option>
          <option value="31">31</option>
        </select>
    </div>

    <div class="selectmenu xsmall-type1 inputDOB">
        <select id="MonthEnd" name="EventFullDateEnd" class="js-selectmenu" data-val="true">
          <option value="">MM</option>
          <option value="01">01</option>
          <option value="02">02</option>
          <option value="03">03</option>
          <option value="04">04</option>
          <option value="05">05</option>
          <option value="06">06</option>
          <option value="07">07</option>
          <option value="08">08</option>
          <option value="09">09</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
        </select>
    </div>


    <input id="EventYearEnd" 
      type="text" 
      name="EventFullDateEnd" 
      class="form_input--inline inputDOB" 
      placeholder="YYYY" 
      data-val-length-max="4" data-val-regex="Event Date is invalid."
      data-val-length="Event Date must be less than 4 characters."
      data-val-daymonthyear="{0} is required." 
      data-val-regex-pattern="^[0-9]*$"  
      maxlength="4" 
      data-val="true" />
    <div class="error-message" role="alert">
      <div class="error-text">
        <p><span class="field-validation-valid" data-valmsg-for="EventFullDateEnd" data-valmsg-replace="true">Please tell us your event end date</span></p>
        <img src="http://res.cloudinary.com/df821af5o/image/upload/v1499521750/mcr-error-bg_wfz31v.png" alt="">
      </div>
    </div>
    <div class="inline-error-message">
        <div class="error-text">
            <p></p>
            
        </div>
    </div>
</div>
              
            
!

CSS

              
                .macmillan-form .field .error-text {
    color: #FFF;
    display: block;
    font-size: 14px;
    padding: 10px;
    position: relative;
    z-index: 2;
}

.error-handler .error-text {
    color: #FFF;
    display: block;
    font-size: 14px;
    padding: 10px;
    position: relative;
    z-index: 2;
}

.error-handler .error-text img {
    width: 100%;
    height: 100%;
    top: 0;
    right: 0;
    position: absolute;
    z-index: -1;
}

error-handler .error-text p {
    font-size: 1em;
    margin: 0;
}

.error-handler .error-message {
    display: block !important;
    margin: 0;
    max-width: 454px;
    width: 100%;
    z-index: 2;
}

.error-message {
    position: relative;
    padding-top: 15px;
    display: none;
}
.error-message {
    position: relative;
    padding-top: 15px;
    display: none;
}
              
            
!

JS

              
                //Event date validation starts here
var validEventDate = true;

$('#Date, #Month, #EventYear').on('change', function() {
    if (validateEventDate()) {
        if ($('#DateEnd').val() === "" && $('#MonthEnd').val() === '' && $('#EventYearEnd').val() === '') {
            handleErrorMessage(true)
            validEventDate = true
            console.log("error2-1")
        } else {
            var startDate1 = new Date($('#EventYear').val() + '-' + $('#Month').val() + '-' + $('#Date').val())
            var endDate1 = new Date($('#EventYearEnd').val() + '-' + $('#MonthEnd').val() + '-' + $('#DateEnd').val())
            if (endDate1 >= startDate1) {
                handleErrorMessage(true)
                validEventDate = true;
                //added later
                handleErrorMessageEnd(true)
                validEventDateEnd = true;
                console.log("error2-2")
            } else {
                validEventDateEnd = false;
                //handleErrorMessageLessthan(false);
              handleErrorMessageEnd(false)
                console.log("error2-3")
            }
            //handleErrorMessageEnd(true)
            //validEventDateEnd = true;
            handleErrorMessage(true)
            validEventDate = true;
            console.log("special-error1")
        }
    } else {
        handleErrorMessage(false)
        validEventDate = false 
        console.log("error2-4")
    }
})

function handleErrorMessage(op) {
    if (!op) {
        $('#EventDate').addClass('error-handler')
        $('#EventDate').find('.error-message').find('.error-text p').html('Please enter a valid event date.')
    } else {
        $('#EventDate').removeClass('error-handler')
        $('#EventDate').find('.error-message').find('.error-text p').html('')
    }
}
function handleErrorMessageLessthan(op) {
    if (!op) {
        $('#EventDate').addClass('error-handler')
        $('#EventDate').find('.error-message').find('.error-text p').html('Please enter a valid event date less than event end date.')
    } else {
        $('#EventDate').removeClass('error-handler')
        $('#EventDate').find('.error-message').find('.error-text p').html('')
    }
}

function validateEventDate() {
    var $day = $('select[id="Date"] option:selected'),
        $month = $('select[id="Month"] option:selected'),
        $year = $('input[id="EventYear"]'),
        dayStr = $day.text(),
        monthStr = $month.text(),
        yearStr = $year.val(),
        dayIndex = $day.index(),
        monthIndex = $month.index(),
        yearIndex = yearStr;

    if (dayIndex > 0 || monthIndex > 0 || yearIndex > 0) {
        if (dayIndex > 0 && monthIndex > 0 && yearIndex > 0) {

            if (dayIndex > 29 && monthIndex == 2) {
                return false
            }

            if ((dayIndex > 30) && (monthIndex == 4 || monthIndex == 6 || monthIndex == 9 || monthIndex == 11)) {
                return false
            }

            eventDate = new Date(yearStr + '/' + monthStr + '/' + dayStr);
            nowDate = new Date();
          
            var holidays = [new Date("2017/12/25"), new Date("2017/12/26"),  new Date("2017/12/27")];
            if (isNaN(eventDate)) {
                return false;
            } else {
                if (eventDate < nowDate || eventDate.getDay() === 6 || eventDate.getDay() === 0 ) {
                    return false;
                } else {
                   // var eventHoliday = holidays.filter(function(holiday) {
                   //  return holiday === eventDate
                   // });
                   for (var i = 0; i < holidays.length; i++) {
                       if (eventDate.getTime() === holidays[i].getTime()) {
                         return false;
                       }
                    }
                  
                    // for (var i = 0; i < holidays.length; i++) {
                    //    if (eventDate.getTime() !== holidays[i].getTime()) {
                    //      console.log('foo');
                    //      return true
                    //    } else {
                    //      return false
                    //    }
                    // }
                   // if (!!eventHoliday) {
                   //     return false
                   //  } else {
                   //    return true
                   //  }
                   return true
                }
            }
        } else {
            return false;
        }
    } else {
        return false;
    }
}
//Event date validation ends here

//Event End date validation starts here
var validEventDateEnd = true;

$('#DateEnd, #MonthEnd, #EventYearEnd').on('change', function() {

    if (validateEventDateEnd()) {
        if ($('#Date').val() === "" && $('#Month').val() === '' && $('#EventYear').val() === '') {
            handleErrorMessage(false)
            validEventDate = false;
            console.log("error0")
        } else {
            var startDate = new Date($('#EventYear').val() + '-' + $('#Month').val() + '-' + $('#Date').val())
            var endDate = new Date($('#EventYearEnd').val() + '-' + $('#MonthEnd').val() + '-' + $('#DateEnd').val())
            console.log("error1")
            if (endDate >= startDate) {
                handleErrorMessageEnd(true)
                validEventDateEnd = true;
                console.log("error2")
              
            } else {
                handleErrorMessageEnd(false)
                validEventDateEnd = false;
                console.log("special-error2")
            }
            console.log("error3")
        }
    } else {
        if ($('#DateEnd').val() === "" && $('#MonthEnd').val() === '' && $('#EventYearEnd').val() === '') {        
            if (validateEventDate() ) {
              handleErrorMessage(true)
              validEventDate = true;
              console.log("error4-1")
             } else {
              handleErrorMessageEnd(false)
              validEventDateEnd = false;
              console.log("error4-2")
             }
          handleErrorMessageEnd(true)
          validEventDateEnd = true;
          console.log("error4")
        } else {
            handleErrorMessageEnd(false)
            validEventDateEnd = false;
            console.log("error5")
        }
    }
})

function handleErrorMessageEnd(op) {
    if (!op) {
        $('#EventDateEnd').addClass('error-handler')
        $('#EventDateEnd').find('.error-message').find('.error-text p').html('Please enter a valid event end date greater or same than the event date.')
    } else {
        $('#EventDateEnd').removeClass('error-handler')
        $('#EventDateEnd').find('.error-message').find('.error-text p').html('')
    }
}

function validateEventDateEnd() {
    var $day = $('select[id="DateEnd"] option:selected'),
        $month = $('select[id="MonthEnd"] option:selected'),
        $year = $('input[id="EventYearEnd"]'),
        dayStr = $day.text(),
        monthStr = $month.text(),
        yearStr = $year.val(),
        dayIndex = $day.index(),
        monthIndex = $month.index(),
        yearIndex = yearStr;

    if (dayIndex > 0 || monthIndex > 0 || yearIndex > 0) {
        if (dayIndex > 0 && monthIndex > 0 && yearIndex > 0) {

            if (dayIndex > 29 && monthIndex == 2) {
                return false
            }

            if ((dayIndex > 30) && (monthIndex == 4 || monthIndex == 6 || monthIndex == 9 || monthIndex == 11)) {
                return false
            }

            eventDate = new Date(yearStr + '/' + monthStr + '/' + dayStr);
            nowDate = new Date();

            if (isNaN(eventDate)) {
                return false;
            } else {
                if (eventDate < nowDate) {
                    return false;
                } else {
                    return true
                }
            }

        } else {
            return false;
        }
    } else {
        return false;
    }
}
//Event End date validation ends here


function navigateToError() {
    var errorDiv = $('.error-message:visible').first();
    var scrollPosition = errorDiv.offset().top - 60;
    $(window).scrollTop(scrollPosition);
}


// For all steps-forms and other forms -Enter key disble submit forms
$('.js-macmillan-stepped-form input').on('keyup keypress',  function(e) {
  var keyCode = e.keyCode || e.which;
  if (keyCode === 13) { 
    e.preventDefault();
    return false;
  }
});
              
            
!
999px

Console