Required Sharepoint fields - alert on save

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

02 Dec 2015

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?

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

03 Dec 2015

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.

Katy
Posts: 145
Joined: Wed Dec 02, 2015
Location: Canada

03 Dec 2015

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

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests