3

I have a date field that's now allowed to be >=TODAY(). But this validation should only be run IF the field have been edited.

The field is present in a form with other fields. And if any of these are chagned but the datefield havent been changed the validation should pass.

Is there anyway to define this?

3

Customize the Edit form (either through SP Designer) or add Content Editor webpart (SP 2010) or Script Editor webpart(SP2013). Add JavaScript code to perform validation. Use SharePoint PreSaveAction() Javascript function. When an item is saved SharePoint calls PreSaveAction(). Here you need to perform the validation. See this for more info: http://www.ilikesharepoint.de/2014/06/sharepoint-presaveaction-helps-for-actions-before-saving-an-item/

2

Using Event Receiver

The only fool proof option is to create an event receiver and handle ItemUpdating handler.

Here you have Before and After properties. You can use that to compare the previous values and new values.

If validation fails you can cancel the update process and redirect user to an error page.

Using JavaScript

This option people can bypass by disabling etc. In this approach you can edit the form in SharePoint designer and add logic as follows

  1. On Page Load get all values and store it in temporary object
  2. Attach a JavaScript click handler to the Save button
  3. On the handler you can compare temporary object with new values
  4. Based on that validation you can cancel the save event

The good thing about this approach is it will give a nice user experience. But its require more effort to built.

0

Isn't it possible to access the current value of a field in the formula? That way I can see if the value have been changed and only validate if it have been changed.

(I'm 100% new to sharepoint)

  • You can't have both previous and current value of the same column in a formula, sorry. Only if you store the previous in another column. – Alexey Krasheninnikov Dec 10 '14 at 8:59
0

I will go for JSLink. Try below

https://code.msdn.microsoft.com/office/Client-side-rendering-code-80cc9b05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.