<tr>
<tr>
    <td>
        <input type="hidden"  id="newFreshId" value="{$record->id}"/>
        <input type="text" class="form-control  datepicker updateElement" data-id="{$record->id}" 
               data-colName="try_date" data-tableName="icsi_fresh" 
               value="{$record->try_date}" readonly />
    </td>
    <td>
        <input type="text" class="form-control  datepicker updateElement" data-id="{$record->id}" 
               data-colName="lmp" data-tableName="icsi_fresh" 
               value="{$record->lmp}" readonly />
    </td>
    <td>
        <select class="form-control  updateElement editModelSel  icsi_protocol"data-colName="icsi_protocol" 
                data-id="{$record->id}"  data-tableName="icsi_fresh"    id="icsi_protocol{$record->id}"
                select-tableName="icsi_protocol" >
            <option value=""></option>
            {foreach $protocols as $data}
            <option value="{$data->id}" {if $record->icsi_protocol eq  $data->id}selected{/if}>{$data->name}</option>
            {/foreach}
            <option value="0" class="deleteoptincompo">حذف</option>
        </select>
    </td>
    <td>
        <select class="form-control  updateElement editModelSel  icsi_trigname"data-colName="icsi_trigname" 
                data-id="{$record->id}"  data-tableName="icsi_fresh"    id="icsi_trigname{$record->id}">
            <option value=""></option>
            {foreach $trignames as $data}
            <option value="{$data->id}" {if $record->icsi_trigname eq  $data->id}selected{/if}>{$data->name}</option>
            {/foreach}
            <option value="0" class="deleteoptincompo">حذف</option>
        </select>
    </td>
    <td>
        <select class="form-control  updateElement editModelSel  icsi_trigday"data-colName="icsi_trigday" 
                data-id="{$record->id}"  data-tableName="icsi_fresh"    id="icsi_trigday{$record->id}">
            <option value=""></option>
            {foreach $trigdays as $data}
            <option value="{$data->id}" {if $record->icsi_trigday eq  $data->id}selected{/if}>{$data->name}</option>
            {/foreach}
            <option value="0" class="deleteoptincompo">حذف</option>
        </select>
    </td>
    <td>
        <input type="text" class="form-control  updateElement" data-id="{$record->id}" 
               data-colName="last_size" data-tableName="icsi_fresh" 
               value="{$record->last_size}"  />
    </td>
    <td>
        <input type="text" class="form-control  updateElement" data-id="{$record->id}" 
               data-colName="mi" data-tableName="icsi_fresh" 
               value="{$record->mi}"  />
    </td>
    <td>
        <input type="text" class="form-control  updateElement" data-id="{$record->id}" 
               data-colName="mii" data-tableName="icsi_fresh" 
               value="{$record->mii}"  />
    </td>
    <td>
        <input type="text" class="form-control  updateElement" data-id="{$record->id}" 
               data-colName="gv" data-tableName="icsi_fresh" 
               value="{$record->gv}" />
    </td>
    <td>
        <input type="text" class="form-control  updateElement" data-id="{$record->id}" 
               data-colName="semen" data-tableName="icsi_fresh" 
               value="{$record->semen}" />
    </td>
    <td>
        <input type="text" class="form-control  updateElement" data-id="{$record->id}" 
               data-colName="embryos" data-tableName="icsi_fresh" 
               value="{$record->embryos}" />
    </td>
    <td>
        <input type="text" class="form-control  updateElement" data-id="{$record->id}" 
               data-colName="groups" data-tableName="icsi_fresh" 
               value="{$record->groups}" />
    </td>
    <td>
        <input type="checkbox"  value="1" class="updateElementCheck" 
               data-id="{$record->id}" data-tableName="icsi_fresh" data-colName="pregnancy"  
               {if {$record->pregnancy}  == 1 } checked {/if}>
    </td>
    <td>
        <textarea class="form-control updateElement txtc" rows="1" data-id="{$record->id}" 
                  data-colName="notes" data-tableName="icsi_fresh" placeholder="Enter more text" 
                  data-toggle="popover" data-trigger="hover" data-placement="bottom" 
                  data-content="{$record->notes}" 
                  >{$record->notes}</textarea>
    </td>
    <td>
        <button class="btn btn-xs red-intense deleteelement " type="button"  data-id="{$record->id}"
                data-link="gyna"  data-fun="deldata" data-tableName="icsi_fresh" 
                ><i class="fa fa-close"></i></button>
    </td>
</tr>
</tr>



{literal}
<script>
    var id = $('#newFreshId').val();
    $('#newFreshId').remove();

    $('.datepicker').datepicker();
    $("#icsi_protocol" + id).select2({
//   width: '240px',
        allowClear: true,
        formatNoMatches: function (term) {
            /* customize the no matches output */
            var thisId = $(this).attr("id");
            return "<input class='form-control' id='newicsi_protocolSelectTerm' value='" + term + "'><a href='#' id='addNewicsi_protocolSelect' data-id='" + thisId + "' class='btn blue custombtnstyle'>ADD</a>"
        }
    }).parent().find('.select2-with-searchbox').on('click', '#addNewicsi_protocolSelect', function () {
        /* add the new term */
        var Protocol = $('#newicsi_protocolSelectTerm').val();
        var thisId = $(this).attr("data-id");
        $.post(hosturl + "/controllers/embryoslab.php?ac=addRow", {value: Protocol, table: 'icsi_protocol'}, function (data) {

            $('.icsi_protocol > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + Protocol + '</option>');
            $('#' + thisId + '').select2('val', Number(data)); // select the new term
            $('.icsi_protocol').select2('close'); // close the dropdown

            $('.updateElement[id=' + thisId + ']').trigger("change");
        });
    });

    $("#icsi_trigname" + id).select2({
//   width: '240px',
        allowClear: true,
        formatNoMatches: function (term) {
            /* customize the no matches output */
            var thisId = $(this).attr("id");
            return "<input class='form-control' id='newicsi_trignameSelectTerm' value='" + term + "'><a href='#' id='addNewicsi_trignameSelect' data-id='" + thisId + "' class='btn blue custombtnstyle'>ADD</a>"
        }
    }).parent().find('.select2-with-searchbox').on('click', '#addNewicsi_trignameSelect', function () {
        /* add the new term */
        var Protocol = $('#newicsi_trignameSelectTerm').val();
        var thisId = $(this).attr("data-id");
        $.post(hosturl + "/controllers/embryoslab.php?ac=addRow", {value: Protocol, table: 'icsi_trigname'}, function (data) {

            $('.icsi_trigname > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + Protocol + '</option>');
            $('#' + thisId + '').select2('val', Number(data)); // select the new term
            $('.icsi_trigname').select2('close'); // close the dropdown

            $('.updateElement[id=' + thisId + ']').trigger("change");
        });
    });

    $("#icsi_trigday" + id).select2({
//   width: '240px',
        allowClear: true,
        formatNoMatches: function (term) {
            /* customize the no matches output */
            var thisId = $(this).attr("id");
            return "<input class='form-control' id='newicsi_trigdaySelectTerm' value='" + term + "'><a href='#' id='addNewicsi_trigdaySelect' data-id='" + thisId + "' class='btn blue custombtnstyle'>ADD</a>"
        }
    }).parent().find('.select2-with-searchbox').on('click', '#addNewicsi_trigdaySelect', function () {
        /* add the new term */
        var Protocol = $('#newicsi_trigdaySelectTerm').val();
        var thisId = $(this).attr("data-id");
        $.post(hosturl + "/controllers/embryoslab.php?ac=addRow", {value: Protocol, table: 'icsi_trigday'}, function (data) {

            $('.icsi_trigday > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + Protocol + '</option>');
            $('#' + thisId + '').select2('val', Number(data)); // select the new term
            $('.icsi_trigday').select2('close'); // close the dropdown

            $('.updateElement[id=' + thisId + ']').trigger("change");
        });
    });

</script>
{/literal}