I am trying to clear/reset form fields which one of them is SummernoteWidget
<form>
{% csrf_token %}
{{ form.as_p }}
<button type="reset" class="btn btn-warning pull-right" id="reset_btn">Reset Fields</button>
<button type="submit" class="btn btn-success pull-right" id="submit-btn">Submit</button>
</form>
<script src='{% static "summernote/summernote.js" %}'></script>
all fields are getting cleared besides the SummernoteWidget.
I have tried with a JavaScript as follows:
<script>
$('#reset_btn').click(function(){
$("#summernote").summernote('reset');
});
</script>
with out good results.
how can I achieve this ?
Related
I'm trying to submit a form to the right route using the action:
<form action="{{ route('document.destroy', $d->id) }}" method="POST" style="display: inline;">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<span type="text" value="" class="btn btn-success" readonly="readonly">
{{ $d->file_name }} ({{ $d->file_size }}) <i class="fa fa-times"></i>
</span>
<button class="btn btn-xs btn-default" type="submit" data-toggle="tooltip" title="Verwijder" onclick="return confirm('Weet je zeker dat je dit document wilt verwijderen')"><i class="fa fa-times"></i></button>
</form>
But yet it links to a different controller. What am I doing wrong?
I also specified the controller in the routes file:
Route::resource('document', 'DocumentController');
To add more context: this view gets passed from a different controller than I want to use for the DELETE function.
EDIT
I used a form inside another form, my stupid head didn't see it.
for deleting you can try this
<form action="{{action('DocumentController#destroy', $d->id)}}" method="post">
{{csrf_field()}}
<input name="_method" type="hidden" value="DELETE">
<button class="btn btn-danger" type="submit">Delete</button>
</form>
and Destroy method
public function destroy($id)
{
$doc= Document::find($id);
$doc->delete();
return redirect('/home')->with('success', 'Document has been deleted!!');
}
After clicking on DELETE, there is no reaction, absolutely nothing happens. I am using HTML Forms, that's why I used, #method('DELETE'). I had similar problem with edit, after using #method(PUT), edit is working properly.
<div class="row">
<div class="col-6 align-self-start">
<a class="btn btn-light" href="/listings/{{$listing->id}}/edit">Edit</a>
</div>
<div class="col-6 align-self-end">
<form action="{{action('ListingsController#destroy', [$listing->id])}}" method="POST">
<?= csrf_field()?>
#method('DELETE')
<a class="btn btn-danger" href="/dashboard">Delete</a>
</form>
</div>
</div>
Destroy Function:
public function destroy($id)
{
$listing = Listing::find($id);
$listing->delete();
return redirect('/dashboard')->with('success', 'Contact Deleted');
}
Change
<a class="btn btn-danger" href="/dashboard">Delete</a>
to
<a type="submit" class="btn btn-danger" href="/dashboard">Delete</a>
You should add submit otherwise it will not submit the form.
Its recommended to use a instead of :
<button type="submit" class="btn btn-danger">Delete</button>
How to make delete function in laravel model, usually when in blade we use :
<form action="{{ action('ItemNameController#destroy', $ItemName->id) }}" method="post">
#csrf
#method("DELETE")
<input type="submit" class="btn btn-danger btn-sm btn-style" href="{{ $ItemName->id }}" value="Delete" onclick="return confirm('Are You Sure To Delete This Item? #{{ $ItemName->inc }} ')">
</form>
So how to write that code when we write it in controller, because in controller cannot to write eloquent or cannot to process (.blade.php)
Example in Controller:
foreach ($i as $value) {
echo "<form action='' method='post'>";
echo "<th><input type='submit' class='btn btn-danger btn-sm btn-style' href=' value='Delete' value='Delete' style='font-size: 10px'></th>";
echo "</form>";
}
You can achieve a this by:
<form action="{{ action('ItemNameController#destroy', $ItemName->id) }}" method="post">
{{csrf_field()}}
<input type="submit" class="btn btn-danger btn-sm btn-style" href="{{ $ItemName->id }}" value="Delete" onclick="return confirm('Are You Sure To Delete This Item? #{{ $ItemName->inc }} ')">
</form>
Where in your controller you would handle the delete method. If you were using an ajax request you could send a delete request to the server.
Your route something like be:
Route::post('/itemname/{ItemName}/delete', 'ItemNameController#destroy');
To stop it being confused with:
Route::post('itemname/{ItemName}', 'ItemNameController#update);
Hope this helps.
I'm having trouble using the destroy method from my resource controller. I know in html you can only POST/GET so I used a hidden value but it comes up with a MethodNotAllowedHttpException error. Here is my code:
Modal where the Delete Button is:
<div class="modal-footer">
<form action="/wod/{{$wod->id}}" method="POST">
{{ csrf_field() }}
{{ method_field('DELTE') }}
<button type="button" class="btn btn-default navbar-inverse" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-default navbar-inverse"><a class="bottom" href="/wod/{{$wod->id}}/edit">Edit</a></button>
<button class="btn btn-primary navbar-inverse" value="submit" type="submit">Delete</button>
</form>
</div>
And here is my resource controller:
public function destroy(Id $id)
{
//
Wod::find($id)->delete();
return redirect()->action("WodController#index");
}
you have a typo in {{ method_field('DELTE') }}
it should be {{ method_field('DELETE') }}
Here is my button:
my $post->comment contained id, comment, email and name;
I want to pass the comment to the form inside the modal.
I also want to use the id to the 2nd parameter of the route to update the comment
#foreach($post->comments as $comment)
<button class="btn btn-success btn-xs " data-toggle="modal" data-target="#myModal" data-id="{{ $comment->id }}" data-comment=" {{ $comment->comment }}"><i class="fa fa-pencil"></i></button>
#endforeach
Here is my modal:
<!-- Modal -->
<div class="modal fade modal-md" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×
</button>
<h4 class="modal-title">Comment Update!</h4>
</div>
<div class="modal-body">
<div id="comment-form" class="">
{{ Form::open(['route' => ['comments.store', $post->id], 'method' => 'POST']) }}
<div class="row">
<div class="col-md-12">
<b>{{ Form::label('comment', "Comment:") }}</b>
{{ Form::textarea('comment', null, ['class' => 'form-control', 'rows' => '5', 'id'=>'comment ']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
<div class="modal-footer">
<a href="{{route('comments.store',$post->id) }}"
onclick="event.preventDefault();
document.getElementById('comment-update').submit();" class="btn btn-primary">
Update </a>
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
I tried this Script but it wont work:
<script type="text/javascript" charset="utf-8">
$('#myModal').on('show', function(e) {
var link = e.relatedTarget();
var id = link.data("id");
var comment = link.data("comment");
var modal = $(this);
modal.find("#id").val(id);
modal.find("#comment").val(comment);
});
you must using on click event in javascript
example:
<button class="btn btn-success btn-xs add" data-toggle="modal" data-target="#myModal" data-id="{{ $comment->id }}" data-comment=" {{ $comment->comment }}"><i class="fa fa-pencil"></i></button>
this script.
$(document).on('click', '.add', function() {
$('#id_kategori').val($(this).data('id'));
$('#comment').val($(this).data('comment'));
$('.form-horizontal').show();
$('#myModal').modal('show');
});
i hope my answer helping you