Page 1 of 1

Alert if Form Save fails

Posted: 20 Apr 2018
by Kim Jeim
Hi,

We have a form that is quite complex - different checks for different kinds of items in the one list when saving.

Most of them have their own alerts built in should a field that is required be missing.

Sometimes a user tries to create a new item and hits save, but because a mandatory field is empty or something else we have not thought of, the form just reloads (having not created the item).

Is there a way to pop up an alert if the new item does not save?

Thanks

Re: Alert if Form Save fails

Posted: 20 Apr 2018
by Nikita Kurguzov
Dear Kim,
That really depends on how complex the form is. There are two possible forms of validation - server validation (always done by SharePoint when the form is sent to the server), and client validation(can be done with JS before the form is sent to the server).

Now, client validation can be added prior to sending form to the server, but it's complexity will depend on the amount of fields that you have and how complex these fields are. For example, if you have a couple of fields - client validation would be very easy to write. If you have around 40 fields, but all of them are simple Text fields - client validation shouldn't be too hard either. If you have all kinds of fields such as Multiline Rich Text, Lookup, Person Field, Managed Metadata, etc. - client validation would be much harder to create.

You can see an example of client validation used in this article - https://spform.com/javascript-framework ... ynamically

If you have questions on what to do with your specific form - feel free to ask! You can also give us screenshots of the form and more information in general, so we can recommend the best approach. What you ask is technically possible, but might require a lot of code to implement.

Re: Alert if Form Save fails

Posted: 26 Apr 2018
by Kim Jeim
Hi Nikita,

Thanks for that. Put another spin on the question, as we are checking using client validation on required fields etc.

User inputs information into all the required field (ace!), but somehow on tab 2, puts in the word "two" when it is actually a numeric field. The form shows it is trying to save but then goes back to the same page. The form specifies the problem in the field on tab 2, but it is not obvious enough to the user, who thinks that the save has gone through. In this instance, it would be helpful if there was a way to say "something went wrong, look for it!"

Is that possible?

Regards,
Tjon Kim

Re: Alert if Form Save fails

Posted: 26 Apr 2018
by Nikita Kurguzov
Dear Kim,
In your validation code, you are not limited to checking if the value is present or not, you can also make sure that the value is numerical or not, for example:

Code: Select all

fd.onsubmit(function(){
	//your other code...

	if(isNaN(fd.field('Num').value())){
            alert("Please, enter a number in the Num field");
            return false;
        }

	return true;
});