Forums

Forums / General Discussions / DateTime Field Required Validation Message

DateTime Field Required Validation Message

9 posts, 1 answered
  1. jahanzaib shahid
    jahanzaib shahid avatar
    8 posts
    Registered:
    08 Dec 2021
    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 jahanzaib shahid
  2. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    Answered
    09 Feb 2022 in reply to jahanzaib shahid
    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 Brady Ward
  3. jahanzaib shahid
    jahanzaib shahid avatar
    8 posts
    Registered:
    08 Dec 2021
    09 Feb 2022 in reply to Brady Ward
    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. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    09 Feb 2022 in reply to jahanzaib shahid
    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. jahanzaib shahid
    jahanzaib shahid avatar
    8 posts
    Registered:
    08 Dec 2021
    09 Feb 2022 in reply to Brady Ward
    Link to this post
    thanks now its working.
  6. jahanzaib shahid
    jahanzaib shahid avatar
    8 posts
    Registered:
    08 Dec 2021
    10 Feb 2022 in reply to Brady Ward
    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. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    10 Feb 2022 in reply to jahanzaib shahid
    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 Brady Ward
  8. ranjhhaheer ranjhhaheer
    ranjhhaheer ranjhhaheer avatar
    1 posts
    Registered:
    11 May 2022
    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 ranjhhaheer ranjhhaheer
  9. Brady Ward
    Brady Ward avatar
    92 posts
    Registered:
    19 Aug 2021
    11 May 2022 in reply to ranjhhaheer ranjhhaheer
    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