I need your help please. I have a scenario where I appending value from the dropdown to the text area. I'm facing an issue where I cannot appending the same value from the dropdown.
For example I write at text area text hello
then insert "User name" then try to insert "User name" again and it dose not inserted.. only another option I can insert. But if I insert another option then I can insert "User name" again.
<select name="email_admin" class="form-control variables_select">
<option value="">--Select--</option>
<option value="user_name">User name</option>
<option value="ticket_number">Ticket #</option>
<option value="ticket_subject">Ticket subject</option>
</select>
$('.variables_select').change(function(){
var current_select_list = $(this).attr('id');
var id = $(this).closest('.panel-body').find('textarea').attr('id');
var cursorPosStart = $('#'+ id).prop('selectionStart');
var cursorPosEnd = $('#'+ id).prop('selectionEnd');
var v = $('#' + id).val();
var textBefore = v.substring(0, cursorPosStart);
var textAfter = v.substring(cursorPosEnd, v.length);
if ($('#' + current_select_list + ' option:selected').val().length > 0) {
$('#' + id).val(textBefore + '{{' + $('#' + current_select_list + ' option:selected').val() + '}}' + textAfter);
}
$('#'+ id).prop('selectionStart', cursorPosStart);
$('#'+ id).prop('selectionEnd', cursorPosStart + '{{' + $('#' + current_select_list + ' option:selected').val() + '}}'.length);
});
html.
<div class="panel-body">
<div class="input-group pull-right margin-bottom-1">
<?php
echo Form::select('templates_variables_logs_staff', $templatesVariables, '', array('class' => 'form-control variables_select'));
?>
</div>
<?php
echo Form::label('logs_staff', __('Content', 'notifications'), array('class' => 'control-label'));
echo Form::textarea('logs_staff', $logs_staff, array('class' => 'form-control'));
?>
</div>