How to update the value of nicEdit textarea

Hi I have a table contains a list of posts and two buttons in each post (delete and edit) .All fields get edited but I can not edit the nicEdit textarea but when I try to edit the first article's textarea it get edited here is my jquery code :

 <script type="text/javascript">
   $(function() {
     $("#myForm").submit(function() {
       $("textarea").each(function(){ 
         new nicEditors.findEditor(this.id).saveContent();
       });
     });
   });
</script>

this is my view :

         @foreach($articles as $post)

            <tr>

            <td>{{$post->title}}</td>
            <td>{{$post->published_at}}</td>
            <td><p data-placement="top" data-toggle="tooltip" title="Edit"><button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit{{$post->id}}" ><span class="fa fa-pencil"></span></button></p></a></td></a>
            <td><p data-placement="top" data-toggle="tooltip" title="Delete"><button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete{{$post->id}}" ><span class="fa fa-trash"></span></button></p></td>
        <div class="modal fade" id="edit{{$post->id}}" tabindex="-1" role="dialog" aria-labelledby="edit" aria-hidden="true">
              <div class="modal-dialog">
            <div class="modal-content">
                  <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
                <h4 class="modal-title custom_align" id="Heading">Edit l'article : {{$post->id}}</h4>
              </div>    
              <div class="modal-body"> 
                          {!! Form::model($post,['method' => 'PATCH','files'=> true,'id'=>'myForm','route' => ['articles.update', $post->id]])!!}

        @include('partials.postForm')

        </div>
</tr> 

    @endforeach

Answers:

Answer

Try this

$("#myForm").submit(function() {
   $("textarea").each(function(){ 
     $(this).val($(this).closest('tr').find('.nicEdit-main').html());
   });
 });

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.