• Resolved totallyhorse

    (@totallyhorse)


    Hello,

    Could someone please help me out? I added a custom question (experience date) that needs to be answered with a valid date instead of text or number (possibilities now-on site review form). The question is required and the date can’t be older than 12 months or in the future. I tried different codes and none is the perfect one. Custom script at the moment:

    jQuery(document).ready(function($) {

    $('input[id^="cr_onsite_"][type="text"]').attr('type', 'date');


    var today = new Date();
    var oneYearAgo = new Date(today);
    oneYearAgo.setFullYear(today.getFullYear() - 1);

    $('input[id^="cr_onsite_"][type="date"]').each(function() {
    $(this).attr('min', oneYearAgo.toISOString().split('T')[0]);
    $(this).attr('max', today.toISOString().split('T')[0]);
    $(this).attr('required', true);
    });


    $('#cr-review-form').on('submit', function(event) {
    var isValid = true;

    $('input[id^="cr_onsite_"][type="date"]').each(function() {
    var dateInput = $(this).val();
    var inputDate = new Date(dateInput);


    if (!dateInput) {
    isValid = false;
    alert('Dit veld mag niet leeg zijn.');
    $(this).focus();
    return false;
    }


    if (inputDate.toString() === 'Invalid Date') {
    isValid = false;
    alert('Voer een geldige datum in.');
    $(this).focus();
    return false;
    }


    if (inputDate < oneYearAgo || inputDate > today) {
    isValid = false;
    alert('De datum moet binnen het afgelopen jaar liggen.');
    $(this).focus();
    return false;
    }
    });


    if (!isValid) {
    event.preventDefault();
    }
    });
    });

    The field can still be send in empty or with a invalid date like 31-09-2024. Is it possible to make this field required again by filling in a date (instead of number or text)?

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support pear8398

    (@pear8398)

    Hi,

    Thanks for using CusRev.

    Supporting the customization code is beyond our scope. I would recommend contacting an expert developer to help you customize the custom question input type.

    Plugin Support bagel1317

    (@bagel1317)

    We haven’t heard from you for more than two weeks. For this reason, I’ll assume that either you are not interested in this question/problem anymore or it has been resolved. If you still require any help, please start a new forum topic.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.