0

We have a custom SharePointFormField for your DisplayForm and DOM Looks like this.

<div class="FormRow">
<div class="FieldLabel">
    <a name="SPBookmark_FileID"></a>
     FileID
     </div>
 <div class="FormField">01-02-20</div>
 </div>
 <div class="FormRow">
<div class="FieldLabel">
    <a name="SPBookmark_Register"></a>
     FileID
     </div>
 <div class="FormField">113</div>
 </div>

I want to replace the this text 01-02-20 with a link. In the jslink file i have a JavaScript Code. How to get the FormField and replace the text ?.

The Problem here is the structure class name is same for all the rows so how to get the div and replace it ?.

0

2 Answers 2

0

If you're to replace "01-02-20" with a link, test out the script below. I'm assuming there would some pattern of the text that you could distinctly identify the div element. In this case, I'm checking the length, since it appears to be a date field.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
  
    $(".FormField").each(function(){
    
    if($(this).text().length==8)
     {
       $(this).text("");
       $(this).append("<a href='https://google.com'>Google</a>");
       
     }
     else
     {
       alert($(this).text());
     }
    
  });
    
  });
});
</script>
</head>
<body>

<div class="FormRow">
<div class="FieldLabel">
    <a name="SPBookmark_FileID"></a>
     FileID
     </div>
 <div class="FormField">01-02-20</div>
 </div>
 <div class="FormRow">
<div class="FieldLabel">
    <a name="SPBookmark_Register"></a>
     FileID
     </div>
 <div class="FormField">113</div>
 </div>

<button>Click me</button>

</body>
</html>



0

Try this:

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script> 
    $(document).ready(function(){ 
        $(".FormField").each(function(){
        if($(this).text()=="01-02-21"){
          $(this).html("<a href='https://google.com'>Google</a>")
        }       
      });
</script>

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.