Page 1 of 1

Required Sharepoint fields - alert on save

Posted: 02 Dec 2015
by Katy
I have a form based on a very big list which has a lot of required/mandatory fields and i need an alert going on Save if any of that fields were not filled out. I found the solution here how to do it, but it means to include all the names of the required Sharepoint fields which is quite a pain. Is there a way to pop out an alert if any of the required fields are empty?

Re: Required Sharepoint fields - alert on save

Posted: 03 Dec 2015
by rostislav
You didn't say how you are doing your validation, so I'll tell you of two ways of doing it:



1. You can make a field mandatory in the column settings and specify validation rule in the list settings: List settings -> Validation settings

2. You can do it with a JavaScript script, it would look something like this:

Code: Select all

fd.onsubmit(function(){

	//here you'll need to include all required fields. bare in mind you'll have to accomodate for different field types, as fields of different types may return different values when they are empty, e.g. a people picker field will return an array, so you'll have to check it's length: fd.field('person').value().length

	if (!(fd.field('field1').value() && fd.field('field2').value()))

	{

		alert('some required field hasn't been filled in');

		return false;

	}

	return true;

}); 
I don't think you can make it much more succinct than that.

Re: Required Sharepoint fields - alert on save

Posted: 03 Dec 2015
by Katy
Thanks Rostislav, I've seen the second solution before, I just thought there is a way to make a condition looks like "if the item is not saved then the alert goes out", but I guess I would have to do insert all the fields