Mandatory date field validation different if using a custom form... why?

We are using SharePoint 2013 and have a custom list in which one of the fields is a mandatory date/time field.  When using the default "New" form, if I don't add any date and click the Save button, the form looks like it is submitted and then comes back with some red text indicating that I need a value for my date/time field.  If I simply create a new custom "New" form, and then click on the Save button without adding my date/time value, I get a black (not red) validation error.  A couple things are going on here.  The error is displayed BEFORE any submit happens, unlike when using the default New form.  The validation message is different and is listed in black rather than red.  For other mandatory fields, the form does get submitted and then displays the validation error in red, although it is a different validation error message than when using the default New form.

I don't care that the text is different, but it is an issue for us that the text is not in red.  Does anyone know why this is happening?

Thanks - Peter

March 4th, 2014 9:16pm

Hi Peter,

According to your description, my understanding is that you want to the alert message is red in the custom New form.

Please open the custom New from in SharePoint web site, and save without type anything in the data field, then the alert message(black) displays. Click on F12 to open IE developer debug tool, click on the arrow , then click on the black message to find the HTML element id for the message, in my test, the id is ctl00_ctl42_g_fed984e8_446c_4fdb_a279_328c2c369be5_ff21_ctl00_ctl00_DateTimeField_ctl00 .

Then click on Settings->Edit page, add a Content Edit web part to the custom New form page, edit the web part and add the following code into the Edit Source of the web part:

<style type="text/css">

#ctl00_ctl42_g_fed984e8_446c_4fdb_a279_328c2c369be5_ff21_ctl00_ctl00_DateTimeField_ctl00{

color:#FF0000;

}

</style>

If you have multiple mandatory fields, you need to find each id for each field alert message, add #id{} into <style > </style> section.

I hope this helps.

Thanks,

Wendy

Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

Free Windows Admin Tool Kit Click here and download it now
March 6th, 2014 2:51am

You can add the below script to system master page and it will work for all event new / edit forms:

$(document).ready(function(){
if(typeof(Page_Validators) !== "undefined") {
$.each(Page_Validators, function(index, element){
var error = "<span class='ms-formvalidation'><span role='alert'>" + element.errormessage + "</span></span>";
$(element).html(error);
})
}
})

April 24th, 2015 11:25am

I am having this same behavior, if I click Save it only validates the Date and Time field and then if I pick a date and click Save it will validate the rest.

But I want all of the required fields to be validated when I click Save and not just the Date and Time.

Free Windows Admin Tool Kit Click here and download it now
April 29th, 2015 6:42pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics