1
I’m having difficulty inserting line breaks in the text that comes as a response from a select in the database through an ajax request.
$('select[name=tipo]').change(function() {
var value = $(this).val();
var _token = $('input[name="_token"]').val();
$.ajax({
url: "{{ route('tipo.getTemplate') }}",
method: "get",
data: {
value: value,
_token: _token
},
success: function(result) {
console.log(result)
$("#template").val(result[0]['conteudo']); //este é o resultado onde quero quebrar linhas
}
})
});
<div class="form-group col-sm-12">
<label class="control-label" >{{ trans('app.email')}}<span class="spancolor">*</span> </label>
<textarea style="height: 200px;" value="" class="form-control" id="template" name="template" placeholder="{{ trans('app.template')}}"></textarea>
</div>
public function getTemplate(Request $request) {
$value = $request->get('value');
$dadosTemplate = DB::table('template')
->select('template.conteudo', 'template.observacao', 'tipoincidente.observacaoincidente')
->join('tipoincidente', 'tipoincidente.id', '=', 'template.idtipoIncidente')
->where('tipoincidente.nome', $value)
->get();
return response()->json($dadosTemplate);
}
Here is the email template, in which I send the text you have in the textarea. This text is in the {{$email variable}}.
<div class="fonte">
<p>Prezados Senhores,</p>
<p>{!!$email!!}</p>
<p>{{$finalizacaodoemail}}</p>
</div>
Code for sending email
$emails = ["[email protected]", "[email protected]"];
$copias = ["[email protected]"];
$beautyemail = app()->make(\Snowfire\Beautymail\Beautymail::class);
$beautyemail->send('dashboard.templateemail', ['email' => $template, 'first_name' => $first_name, 'last_name' => $last_name, 'cargo' => $cargo, 'phone' => $phone, 'ramal' => $ramal, 'finalizacaodoemail' => $finalizacaodoemail], function($m) use ($emails, $assunto, $copias, $template, $finalizacaodoemail)
{
$m->to($emails)->subject($assunto)->from("[email protected]", "Lorena Dutra")->cc($copias, "email cópia");
});
Why exactly do you want to insert this line break? Sometimes there is an easier way to achieve the same goal. Are you having problems with text placement in some div?
– Leandro Castro
Because the text that comes in the textarea is sent by email, I will update the question by adding the email template that I am using. When sent by email the text goes all together without line breaks, I would like each "." to have a break.
– Lorena