Forums

Forums / General Discussions / DateTime Field Required Validation Message

DateTime Field Required Validation Message

9 posts, 1 answered
  1. Missing user
    Missing user avatar
    09 Feb 2022
    Link to this post
    I am using TPC datetime required field but its giving "Required field" error message when we enter only alphabets or numbers how to change that validation message to "invalid format". 
    Last modified on 09 Feb 2022 12:02 by Missing user
  2. Missing user
    Missing user avatar
    Answered
    09 Feb 2022 in reply to Missing user
    Link to this post
    Hello Jahanzaib,

    You can use the following code snippet with minor edits to the selected form, the format and validation message:

    $(document).on("tpc:ready", function(event, tpcObject){
        tpc.forms[0].$$instance.get_kendoValidator().options.rules.dateValidation = function (input, params) {
            if (input.is("[data-role='datepicker']") && input.val() != "") {
                input.attr("data-datevalidation-msg", "You must use the following format: MM/dd/yyyy");
                var date = kendo.parseDate(input.val(), "MM/dd/yyyy");
                if (date) {
                    return true;
                }
                return false;
            }
            return true;                    
        }
    });

    The above code must be placed before the closing body tag if using a built-in JavaScript widget or loaded as late as possible if external (to ensure TPC and jQuery are loaded). In tpc.forms[0] make sure you are selecting the correct form, if there are multiple on the page and update the data-validation-msg AND parseDate format if you are using a different format.

    Let me know if you have any trouble implementing the above,

    Brady
    TPC Web Developer
    Last modified on 09 Feb 2022 14:02 by Missing user
  3. Missing user
    Missing user avatar
    09 Feb 2022 in reply to Missing user
    Link to this post
    hello brady,
    I am using this date format "Saturday, February 05, 2022" how to alter this format "MM/dd/yyyy".
  4. Missing user
    Missing user avatar
    09 Feb 2022 in reply to Missing user
    Link to this post
    Hello again Jahanzaib,

    You would need to use the following format: dddd, MMMM dd, yyyy

    Make sure the format is set on the widget as well as in the custom code.

    Kind regards,

    Brady
    TPC Web Developer
  5. Missing user
    Missing user avatar
    09 Feb 2022 in reply to Missing user
    Link to this post
    thanks now its working.
  6. Missing user
    Missing user avatar
    10 Feb 2022 in reply to Missing user
    Link to this post
    Hi Brady,
    Could you please tell me if I have multiple DateTime Field on a single form your code work only for one field so how to achieve this task ?
  7. Missing user
    Missing user avatar
    10 Feb 2022 in reply to Missing user
    Link to this post
    Hello Jahanzaib,

    A quick solution would be to edit the widget, expand the More Options menu and add a unique class. You can then update the code to the following:

    $(document).on("tpc:ready", function(event, tpcObject){
        tpc.forms[0].$$instance.get_kendoValidator().options.rules.dateValidation = function (input, params) {
            if (input.is("[data-role='datepicker']") && input.val() != "" && input.parents(".UNIQUE_CLASS")) {
                input.attr("data-datevalidation-msg", "You must use the following format: MM/dd/yyyy");
                var date = kendo.parseDate(input.val(), "MM/dd/yyyy");
                if (date) {
                    return true;
                }
                return false;
            }
            return true;                    
        }
    });

    Changing UNIQUE_CLASS to the name of the class you added in the More Options menu.

    Kind regards,

    Brady
    TPC Web Developer
    Last modified on 10 Feb 2022 15:02 by Missing user
  8. Missing user
    Missing user avatar
    11 May 2022
    Link to this post
    I am using this date format "Saturday, February 05, 2022" how to alter this format "MM/dd/yyyy".

    https://get-vidmateapp.com/home/

    https://get-mobdroapk.com



    Last modified on 13 May 2022 07:05 by Missing user
  9. Missing user
    Missing user avatar
    11 May 2022 in reply to Missing user
    Link to this post
    Hi Ranjhhaheer,

    Please see the reply above, I already answered the same question.

    You would need to use the following format: dddd, MMMM dd, yyyy.

    You can view a full list of formatting codes here: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings

    Hope that helps,

    Brady
    TPC Web Developer
9 posts, 1 answered