Code Bug Fix: how to clone row and create new radio button name (keep every radio button group name unique)

Original Source Link

how to clone new row (the sub element radio button name )

html jinja2 (use for loop from json file item that use python process make)
like

                {% for i in data %}
                    <tr class="tr_clone">
                        <td id="td_id_{{ loop.index }}" scope="row" class="member_data_title td_id">
                            <span class="td_id_span">{{loop.index}}</span>
                        </td>
                        <td id="td_logic_{{ loop.index }}" scope="row" class="member_data_title td_logic">
                            <label for="login_and">AND</label>
                            <input type="radio" id="login_and_{{ loop.index }}" name="logic_{{ loop.index }}" {{'value=1 checked="checked" ' if i['Logic'] == 'AND' else 'value="0"'}}>
                            <label for="logic_not">NOT</label>
                            <input type="radio" id="login_not_{{ loop.index }}" name="logic_{{ loop.index }}" {{'value=1 checked="checked" ' if i['Logic'] == 'NOT' else 'value="0"'}}>
                        </td>
                        <td id="td_StudyDescription_{{ loop.index }}" scope="row" class="member_data_title td_StudyDescription">
                            <input type="text" id="StudyDescription_{{ loop.index }}" name="StudyDescription_{{ loop.index }}" value="{{i["StudyDescription"]}}">
                        </td>
                        <td id="td_SeriesDescription_{{ loop.index }}" scope="row" class="member_data_title td_SeriesDescription">
                            <input type="text" id="SeriesDescription_{{ loop.index }}" name="SeriesDescription_{{ loop.index }}" value="{{i["SeriesDescription"]}}">
                        </td>
                        <td id="td_ImageComments_{{ loop.index }}" scope="row" class="member_data_title td_ImageComments">
                            <input type="text" id="ImageComments_{{ loop.index }}" name="ImageComments_{{ loop.index }}" value="{{i["ImageComments"]}}">
                        </td>

                        <td id="td_btnRuleDelete_{{ loop.index }}" scope="row" class="member_data_title td_btnRuleDelete">
                            <input type="button" id="btnRuleDelete_{{ loop.index }}" name="btnRuleDelete_{{ loop.index }}" value="Delete" class="td_btnRuleDelete_btn">
                        </td>
                    </tr>
                {% endfor %}

script part

 <script>
      $(document).ready(function () {
          $('#btnAddRow').click(function(){
            var $lastRow = $("tr:last"); //grab row before the last row
            var $newRow = $lastRow.clone(); //clone it
            $newRow.find(":text").val(""); //clear out textbox values
            $newRow.find(".td_id_span").text(""); //clear out textbox values
            $newRow.find(".td_btnRuleDelete_btn").remove()
            $newRow.find("radio").attr("name","new")
            $lastRow.after($newRow); //add in the new row at the end
          })

          $('.td_btnRuleDelete_btn').click(function(){
               $(this).closest('tr').remove();
          })
      })
    </script>

hope want add rule new row (raido button part) like

   <tr>
    <td id="td_logic_4" scope="row" class="member_data_title td_logic">
        <label for="login_and">AND</label>
        <input type="radio" id="login_and_4" name="login_and_4" value="" checked>
        <label for="logic_not">NOT</label>
        <input type="radio" id="login_not_4" name="login_not_4" value="">
    </td>
   </tr>

before i click Add Rule
enter image description here
after i click Add Rule
enter image description here

my record id 3 radio button miss name ,then radio check turn to empty

Tagged : / / / /

Leave a Reply

Your email address will not be published. Required fields are marked *