2

It seems that Site Columns defined as Type="Choice" ignore the Required="TRUE" attribute when it comes to form validation on the Edit/New pages. In this sceanrio, I chose to not define a default value because I need the user to explicitly read and select a value...yet the form still saves when the field is left blank.

Is this expected behavior and is there a work-around? I am developing my feature in Visual Studio so whatever the solution is, it needs to be implemented in a way that can be deployed as a feature.

More Info

Here is my original field definition

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field
    ID="{5f8fe565-f627-4aed-b7b1-48e5bd2ec8ac}"
    Name="TechnicalReviewAction"
    DisplayName="Technical Review Action"
    Type="Choice"
    Required="TRUE"
    Format="Dropdown"
    FillInChoice="FALSE"
    Group="Knowledge Base Articles">
    <Default></Default>
    <CHOICES>
        <CHOICE>Publish</CHOICE>
        <CHOICE>Revise</CHOICE>
        <CHOICE>Reject</CHOICE>
    </CHOICES>
</Field>

I have tried it with different combinations of including/excluding empty Default element and the FillInChoice element.

Here is the definition in the content type

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Parent ContentType: Workflow Task (0x010801) -->
<ContentType ID="0x010801003EE4B5580C5846B6BE74BFC41A663388"
             Name="Technical Review Task"
             Group="KB Article"
             Description="Content Type for Technical Review Tasks in KB Workflow"
             Inherits="TRUE"
             Version="0">
    <FieldRefs>
        <FieldRef ID="{5f8fe565-f627-4aed-b7b1-48e5bd2ec8ac}"
                  Name="TechnicalReviewAction"
                  DisplayName="Action" />
        <FieldRef ID="{5f4f08ad-7f5b-4d5d-879c-50b416acae3d}"
                  Name="ActionComment" />
    </FieldRefs>
</ContentType>

And here is a screenshot of the form. As you can see there is no asterisks indicating a required field and of course the form saves without entering a value.

Missing required field indicator

  • Remove <Default></Default>. I've also updated my answer. – Robert Kaucher Feb 24 '14 at 19:42
  • I just saw that you said you tried excluding it. This sounds very strange. You are not using a custom new form are you? – Robert Kaucher Feb 24 '14 at 19:59
  • Not yet. My end-game is to use a custom form but I was trying to get this to work first. Here is an odd thing -- I just got it to work by adding the Required="TRUE" to the FieldRef in the ContentType declaration. I thought properties were inherited? – Jason Feb 24 '14 at 22:14
  • I did as well. Add that as an answer! – Robert Kaucher Feb 25 '14 at 0:53
  • Robert -- Can you clarify that inheritance question? When you define a Field and then reference that field in a Content Type, which properties need to be repeated? All of them? Are the defined property values not copied from the original field definition? – Jason Feb 25 '14 at 4:11
2

This is not normal if your definition is correct. Could you post it?

Update: <Default></Default> <= Get rid of that.

<Field Type="Choice" 
       DisplayName="Test_Field" 
       Required="TRUE" 
       EnforceUniqueValues="FALSE" 
       Indexed="FALSE" 
       Format="Dropdown" 
       FillInChoice="FALSE" 
       ID="{f2b25ba8-ca63-4374-9eb3-7a6da830cd6a}" 
       StaticName="Test_Field"
       Name="Test Item">
   <CHOICES>
      <CHOICE>Enter Choice #1</CHOICE>
      <CHOICE>Enter Choice #2</CHOICE>
      <CHOICE>Enter Choice #3</CHOICE>
   </CHOICES>
</Field>

Notice here I do not have DefaultValue in my definition at all. If you put DefaultValue="", that will likely mess up definition. That's the only suggestion as to what I think might cause this issue.

A value is required

A value is required

  • I apologize for the delayed response. I was pulled to some other projects and also had to deal with a solution caching problem with SharePoint that kept me from uploading modified fields. I updated my original posting with the field definitions. – Jason Feb 24 '14 at 18:39
0

Are you not putting a line for default value? or are you setting DefaultValue="" ? I believe you require the latter in order for this to work.

  • @Tal -- The use of a default value negates the need for the Required attribute. As I stated in the original posting, I DO NOT want to define a default value...I want the user to HAVE TO pick one of the available choices but I do not want to give them the ability to save the task without selecting. – Jason Feb 11 '14 at 22:06
0

It seems that some field properties are not inherited when referenced within Content Types. So although I had Required="TRUE" set in my Field, I also had to add it to the FieldRef of the Content Type.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Parent ContentType: Workflow Task (0x010801) -->
<ContentType ID="0x010801003EE4B5580C5846B6BE74BFC41A663388"
             Name="Technical Review Task"
             Group="KB Article"
             Description="Content Type for Technical Review Tasks in KB Workflow"
             Inherits="TRUE"
             Version="0">
    <FieldRefs>
        <FieldRef ID="{5f8fe565-f627-4aed-b7b1-48e5bd2ec8ac}"
                  Name="TechnicalReviewAction"
                  DisplayName="Action"
                  Required="TRUE" /> <!-- This needs to be explicitly set...cannot use setting from Field definition -->
        <FieldRef ID="{5f4f08ad-7f5b-4d5d-879c-50b416acae3d}"
                  Name="ActionComment" />
    </FieldRefs>
</ContentType>

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.