0

I have a list that tracks compliance information. There are two required fields (Evidence and Comments); however, there's no way for the user to know what should go in these fields until they have completed the task. I don't want the user to put "dummy" information in the field when they first create the task (which would usually be before they complete the task), because then when they update the task, they may forget or ignore completing the fields.

Any suggestions?

1
  • Can you provide your user's with example data for the two fields, in advance? What is the list used for? Is it a log of events that occurred in the past or a list of tasks to be completed in the future?
    – Phil Greer
    Commented Apr 29, 2014 at 14:57

2 Answers 2

1

For achieving this you will have to cheat SharePoint OOB forms using jQuery (or javascript).

  1. Add the fields in your list and mark them non-mendatory.
  2. Update the NewForm.aspx to include a jQuery script to hide the non-mandatory fields. .
  3. Update the EditForm.aspx page to include another jQuery script that will check your field values and have custom logic for making the fields as mandatory.

Some References:

4
  • Agreed - Sudhir beat me to it. The way to do this is add scripts to the default forms. The fields won't be required as far as SharePoint is concerned (at the list column level) but the form itself won't submit if the fields are left empty. And don't forget to add some sort of visual indicator or error description when that happens.
    – Omegacron
    Commented Apr 29, 2014 at 17:08
  • +1 to @Omegacron make sure in the Edit form you include some indicator for form validation. Commented Apr 29, 2014 at 17:41
  • @wilson mark it as answer if it helped you. Commented Apr 29, 2014 at 17:42
  • Thank you! I will have to send this to our team and see if they can implement.
    – Nicole
    Commented Apr 29, 2014 at 19:56
0

Note: this answer works as long as none of the fields in question are any of the following types:

  • Multiple lines of text
  • Multiple Choice (i.e. checkboxes; radio button/dropdown is OK)
  • Lookup
  • Person/Group
  • Hyperlink
  • External Data
  • Managed Metadata

If your conditionally-required fields are of one of these types, see Sudhir's answer.


You could use jQuery and/or JavaScript to hide/validate the fields, display validation messages, etc., but that's kind of like killing a fly with a bazooka. A much simpler solution is to use the OOTB List Validation Settings to check for a particular combination of field values.

In your example, you want Evidence and Comments to be optional, unless the task's Status is Completed. This can be achieved with the following list validation formula:

=IF(Status="Completed",NOT(OR(ISEMPTY(Evidence),ISEMPTY(Comments))),TRUE)

What's going on here? Let's break it down:

OR(ISEMPTY(Evidence),ISEMPTY(Comments))   // evaluates to TRUE if either field is empty

NOT(OR(...))                              // inverts the above result - FALSE if either
                                          // field is empty

IF(Status="Completed",NOT(...),TRUE)      // if Status is "Completed", evaluates the NOT
                                          // function above. Otherwise, returns TRUE

When the user tries to save the form, if the list validation formula returns TRUE, the operation completes normally. But if the validation formula returns FALSE, the user will not be able to commit the changes. Enter an explanation, such as "Completed tasks require information in both the Comments and Evidence fields." into the User Message box in the List Validation settings page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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