문제

I have this validation formula that will make a field mandatory base on the choice of the user

=IF([Column1]="Completed",AND(NOT(ISBLANK([Column2]))),TRUE)

But this can only be applied on the columns of the list.

What I want to be mandatory is the attached file ribbon base on the choices of the user.

Thank you!

도움이 되었습니까?

해결책

You can do this by adding link to Javascript in content editor web part on the Newform.aspx Steps to make attachment mandatory based on column value.

  1. Create a choice column. I have created ‘Status’
  2. Create a text column. I have created “Description”
  3. Copy the code below and paste in text file and save it as Test.js inside Layouts folder. Replace the column names (internal column names) with yours in the code and update the javascript links in the code below.

    <script type="text/javascript" src=".../jquery-1.10.2.js" ></script>
    <script type="text/javascript" src=".../jquery.SPServices-2014.01.min.js" ></script>
    <script type="text/javascript" src=".../sputility.min.js"></script>
    
    <script type="text/javascript">
    $(document).ready(function() {
    }); 
    
    
    function PreSaveAction() 
    {
        var column1 = SPUtility.GetSPField('Status'); 
        var column2 = SPUtility.GetSPField('Description'); 
    
        if ( (column1.GetValue().trim() == "Completed") && (column2.GetValue().trim() != "") )
        {
            // make attachment mandatory now
            var elm = document.getElementById("idAttachmentsTable");
            if (elm == null || elm.rows.length == 0)
            {
                document.getElementById("idAttachmentsRow").style.display='none';
                alert("Please attach supporting documents");
                return false ;
            }
            else 
            { 
                return true ;
            }
        }
        else 
        { 
            return true ;
        }
    } 
    
    
    
    
    
    </script> 
    
  4. Go to your list and select ‘Default new form” from the ribbon. enter image description here

  5. Add content editor webpart and link it to Test,js folder in layouts enter image description here

  6. Now alert message will be displayed if Status column is “Completed” and description is not empty. enter image description here enter image description here
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top