3

I have created a custom list with below two columns. 1. Choice with Yes/No values 2. Multiple lines of text

In New Item form of this list, on click of save button I want to make field 2 mandatory only when "Yes" is checked in field 1. Please let me know how can i achieve this and please excuse me for such a novice question, I am really very new in sharepoint. Thanks in advance.

migrated from stackoverflow.com May 10 '12 at 10:07

This question came from our site for professional and enthusiast programmers.

2

An event Receiver would indeed a possible solution here.You'd then override the ItemAdding event checking the Checkbox field value if yes and textbox is empty then cancle event firing and return false. Something like this:

  properties.Cancel = true;
  properties.ErrorMessage = "Item Must Required";
  properties.Status = SPEventReceiverStatus.CancelWithError; 

Let me know if u done with this.

2

In list settings you can only set, that field is either required or not.

To do some more advanced logic, you probably would need to create Custom Field, and write your own validation based on values from another field.

Use of Event Receivers is of course another way.

  • Thanks for your answer, could you please provide some more information? Right now i am using PreSaveAction() function and in this function i am taking handle of the fields by id, took id from the web page source. also let me know if it is not a good way of doing this.. – NotesArt May 10 '12 at 8:58
1

Unfortunately multiple lines of text fields are not allowed in formulars.

If you can change Field2 to a single line of text then you can add a validation saying =OR(NOT(Field1),Field2>"")

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.