Add script to the rich text box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vincent
    Senior Member
    • May 2017
    • 176

    Add script to the rich text box

    We are now working on migrating the paper form to EspoCRM. There are some tables in the form and we found that tables can be made in the rich text field. Drop down list is added to limit the options of some fields in table and dropdown list will also be added to new row.

    below is the code of the richtext field

    <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
    <table class="table table-bordered" cellspacing="0" bordercolor="black">
    <tbody><thead><td><b><u>Description<br></u></b></td><td><b><u>Security LV. #<br></u></b></td><td><b><u>Server Name/Address *<br></u></b></td><td><b><u>Database<br></u></b></td><td><b><u>Login<br></u></b></td><td><b><u>Action (A/U/D)</u></b><br></td></thead>
    <tr><td><input/><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr>
    <tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr>
    <tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr>
    <tr><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td><td><br></td></tr>
    </tbody></table>

    <script>
    function addSecurityLevel(){
    $("table tbody tr td:nth-child(2)").each(function(){
    if ($(this).html().match(/(^<br\s*\/?>|<br\s*\/?>$)/i)){
    $(this).html('<select><option value="1">1</option><option value="5">5</option><option value="10">10</option>');
    }
    });
    }

    $("table").on("DOMSubtreeModified", function (){
    addSecurityLevel();
    });

    addSecurityLevel();
    </script>

    after richtext box saved, code is changed as below:


    <table class="table table-bordered" cellspacing="0" bordercolor="black">
    <tbody></tbody><thead><tr><td><b><u>Description<br></u></b></td><td><b><u>Security LV. #<br></u></b></td><td><b><u>Server Name/Address *<br></u></b></td><td><b><u>Database<br></u></b></td><td><b><u>Login<br></u></b></td><td><b><u>Action (A/U/D)</u></b><br></td></tr></thead>
    <tbody><tr><td><input><br></td><td><select><option value="1">1</option><option value="5">5</option><option value="10">10</option></select></td><td><br></td><td><br></td><td><br></td><td><br></td></tr>
    <tr><td><br></td><td><select><option value="1">1</option><option value="5">5</option><option value="10">10</option></select></td><td><br></td><td><br></td><td><br></td><td><br></td></tr>
    <tr><td><br></td><td><select><option value="1">1</option><option value="5">5</option><option value="10">10</option></select></td><td><br></td><td><br></td><td><br></td><td><br></td></tr>
    <tr><td><br></td><td><select><option value="1">1</option><option value="5">5</option><option value="10">10</option></select></td><td><br></td><td><br></td><td><br></td><td><br></td></tr>
    </tbody></table>


    function addSecurityLevel(){
    $("table tbody tr td:nth-child(2)").each(function(){
    if ($(this).html().match(/(^<br\s*\ ?="">|<br\s*\ ?="">$)/i)){
    $(this).html('<select><option value="1">1</option><option value="5">5</option><option value="10">10</option>');
    }
    });
    }

    $("table").on("DOMSubtreeModified", function (){
    addSecurityLevel();
    });

    addSecurityLevel();

    </select></br\s*\></br\s*\>

    It seems that script is not allowed in the rich text field, am i right?
    How can we add drop down list to table and the drop down list will also shown in the new row? thanks.
  • tanya
    Senior Member
    • Jun 2014
    • 4308

    #2
    Hi,
    it is a wysiwyg field, only for displaying formatted text, not for interactive form.

    I propose you to create standard fields, separate them in the panels with Layout Manager. If you want to print them in a table, you can do it in PDF template.
    In this case data could be filtered by these fields, if you need.

    But if you need it in one field (also think, how do you want to store this data), you can create a view for this field. It could be not easy. As example, check how does Opportunity Items and Quote Items fields are implemented

    Comment

    • Vincent
      Senior Member
      • May 2017
      • 176

      #3
      Originally posted by tanya
      I propose you to create standard fields, separate them in the panels with Layout Manager. If you want to print them in a table, you can do it in PDF template.
      In this case data could be filtered by these fields, if you need.
      We want to input variable number of records, it depends on user. how can i do it using standard fields? thanks.


      Comment

      • tanya
        Senior Member
        • Jun 2014
        • 4308

        #4
        with dynamic logic?
        if it's possible share the example, what you need

        Comment

        • Vincent
          Senior Member
          • May 2017
          • 176

          #5
          We want to add a table in the detail view (like the attached photo) for input. User may add new rows if there are more than 4 rows needed

          Comment

          • tanya
            Senior Member
            • Jun 2014
            • 4308

            #6
            You can create for this another entity and create a relationship one-to-many and relationship panel will be used for it

            Comment

            Working...