You are viewing limited content. For full access, please sign in.

Question

Question

Force Rich Text field to default value

asked on April 10, 2023

I have a Rich Text field that I want to be able to reset to the default value.  I can see the default value in the HTML, like so:

<div id="RTFEditor-Field123" name="RTFEditor123" class="rich-text-editor" style="height:200px" type="richtext" vo="u" default-val="<p>There is a paragraph here...</p><p><br></p><ul><li>And a bullet point here</li><li>Another bullet point here</li><p>etc...</p>"</div>

Assuming I use a "Restore Default Value" button to trigger the function, how can I replace the current contents with the default value?  I have the beginnings of a function using javascript (on Forms 11, using Classic Designer), but if anyone has other suggestions I'd be open to them!
 

$(document).ready (function () {

const resetRTField = function resetRTField (){
  var $rtField = $('li[attr="My_RichText_Field"] div[type="richtext"]');
  

  // I can find the div mentioned above like so, but am not sure how to parse out the default value element
  var defaultValue = $rtField[0].children[1];//.getmethedefaultvalue

  

// now replace the current rich text with the default value rich text

// ....?


}

  $('.resetField').on('click', resetRTField );

});

 

0 0

Answer

SELECTED ANSWER
replied on April 10, 2023 Show version history

I just tested this on Classic Designer Version 11.0.2212.30907 (note that I just tested the form preview, I didn't test through form submission or anything like that).

I gave the Rich Text field a class of myField.

I added a custom HTML element: 

<button type="button" id="resetMyField">Click to Reset the Rich Text Field</button>

 

Then I added the following Javascript: 

$(document).ready(function() {
  
  //When the reset button is clicked, reset the rich text field with
  //the myField class to its default value.
  $('#resetMyField').click(function() {
    var defaultValue = $('.myField .rich-text-editor').attr('default-val');
    $('.myField .rich-text-editor').prop('innerHTML', defaultValue);
  });
  
});

 

When clicking the button, it resets the field contents to match the original default.

2 0
replied on April 11, 2023

Thanks Matthew, that did the job!  It's so simple once I see it... appreciate the help!

1 0
replied on April 11, 2023

You're welcome.

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.