Actually am trying to implement custom actions buttons (In my case using a tag) in my datatable. here i want when user click on delete link then i want a confirm box saying "Are you sure" or something like that.
public function dataTable($query)
{
$editUrl = route('signup.index');
// <a class="btn btn-info waves-effect" href="'.$editUrl.'/{{$id}}/delete">Delete1</a>
if(Auth::user()->hasRole('Super Admin'))
return datatables()
->eloquent($query)
->addColumn('action', '<a class="btn btn-info waves-effect" href="'.$editUrl.'/{{$id}}/delete" onclick="return confirm(1)">Delete</a>');
else
return datatables()
->eloquent($query);
}
Now Here when i click on delete link then it is working fine But when i pass any string in confirm function then the confimation not working.
public function dataTable($query)
{
$editUrl = route('signup.index');
// <a class="btn btn-info waves-effect" href="'.$editUrl.'/{{$id}}/delete">Delete1</a>
if(Auth::user()->hasRole('Super Admin'))
return datatables()
->eloquent($query)
->addColumn('action', '<a class="btn btn-info waves-effect" href="'.$editUrl.'/{{$id}}/delete" onclick="return confirm("Are you Sure")">Delete</a>') //This is not working;
else
return datatables()
->eloquent($query);
}
is there any other approach for this, thanx in advance.
You have a double quote " issue at onclick="return confirm("Are you Sure")". Just using another type of quote for the string then it will work as expected. Something like:
onclick="return confirm(`Are you Sure`)"
Related
I have on my delete function a message for confirmation of delete when i put ok nothing is done
Function from controller
public function destroy($id)
{
$client =client::find($id);
$client->delete();
return redirect('client');
}
view client
<form action="{{url ('client/'.$client->id)}}" method="post">
{{csrf_field()}}
{{method_field('DELETE')}}
<a href="{{url('client/'.$client->id.'/show')}}"
class="btn btn-default btn-sm">Details</a>
<a href="{{url('client/'.$client->id.'/edit')}}"
class="btn btn-primary btn-sm">Editer</a>
<a class="btn btn-danger btn-sm" title="Delete"
href="javascript:if(confirm('Are you sure want to
delete?')) $('#frm_{{$client->id}}').submit()">
Supprimer
</a>
</form>
in your route file just change like this
Route::get('/client/{id}/delete', 'ClientController#destroy');
in your view
Delete
$('#frm_{{$client->id}}').submit() is a jQuery code, are you sure your page have jQuery properly loaded?
Better use plain javascript: document.getElementById("myForm").submit()
i think you forget to add id attribute for you form
<form action="{{url ('client/'.$client->id)}}" id="frm_{{$client->id}}" method="DELETE">
This can be done easily by:
<a onclick="if(confirm('Are you sure you want to delete this item?')){ deleteFunction() };">Delete</a>
I have a modal but I don't want to show it unless it ends doing all the validation.
So am I trying to hide it in the beginning and show it if it passes through the validation process..
My code still shows the modal when I click the btnSubmit
$('#btnSubmit').click(function(e) {
e.preventDefault();
$('#creationModal').modal('hide');
//if the flow is not validated
var flowName = $('#flowName').val();
//check if it exists
validateFlowName(flowName);
});
function validateFlowName(flowName) {
if //some validation processes)
{
}
//if passes all validations, show it
else {
$('#creationModal').modal('show');
}
<button type="submit" class="btn btn-rounded btn-success-outline top10" data-target="#creationModal" data-toggle="modal" id="btnSubmit"><span class="fa fa-plus"></span> Create</button>
When page is load, at that time $('#creationModal').hide() will hide your element and then you will click on button $('#btnSubmit').click(function(e) will call. In this function you can check the condition like this :
$('#creationModal').hide();
$('#btnSubmit').click(function(e) {
e.preventDefault();
//if the flow is not validated
var flowName = $('#flowName').val();
//check if it exists
if(flowName) {
$('#creationModal').show();
}
else {
$('#creationModal').hide();
}
});
Remove data-target="#creationModal" data-toggle="modal" line of code from your button, because this line will open modal. Above line is required if you want open modal directly.
<button type="submit" class="btn btn-rounded btn-success-outline top10" id="btnSubmit"><span class="fa fa-plus"></span> Create</button>
try removing the data-target="#creationModal" data-toggle="modal" from your button :
<button type="submit" class="btn btn-rounded btn-success-outline top10" id="btnSubmit"><span class="fa fa-plus"></span> Create</button>
How to disable a button on click and replace that button with another button with different function using AngularJS?
The following is my button,
<button type="submit" class="btn btn-small btn-default"
ng-disabled="isteam==0 || secondEdit" ng-click="editSetting()">
<span class="glyphicon glyphicon-edit"></span> Edit Setting</button>
you can use a state setting, say $scope.showFirstButton=true to control when to show the submit button:
<button ng-show="showFirstButton" type="submit" class="btn btn-small btn-default" ng-disabled="isteam==0 || secondEdit" ng-click="editSetting()">Edit Setting</button>
and another button, showing them alternatively:
<button ng-show="!showFirstButton" type="submit" class="btn btn-small btn-default" ng-click="doSomethingElse()">Seccond Button</button>
In the controller method $scope.editSetting() you change the value of the state: $scope.showFirstButton = !$scope.showFirstButton'.
Edit: if you need to revert the state of the buttons, do the same thing in the second method:
$scope.doSomethingElse = function(){
//some cool things happen here, and:
$scope.showFirstButton = !$scope.showFirstButton
}
and this will get back the first button and hide the second.
well guys i need to know how give a button a name like dont paye attention to the link it's not that necessary:
<button class="btn btn-success pull-right" name="next">Suivant</button>
here what i did in javascript but i need to add the attribute "name" with value "next" in "q" button
function(a){a.fn.smartWizard=function(m){var c=a.extend({},a.fn.smartWizard.defaults,m),x=arguments;
return this.each(function(){function C(){var e=b.children("div");
b.children("ul").addClass("anchor");
e.addClass("content");
n=a("<div>Loading</div>").addClass("loader");
k=a("<div></div>").addClass("actionBar");
p=a("<div></div>").addClass("stepContainer");
q=a("<a>"+c.labelNext+"</a>").attr("href","#").addClass("btn btn-default pull-right");
r=a("<a>"+c.labelPrevious+"</a>").attr("href","#").addClass("btn btn-default pull-left");
s=a("<a>"+c.labelFinish+"</a>").attr("href","#").addClass("btn btn-success pull-right");
c.errorSteps&&0<c.errorSteps.length&&a.each(c.errorSteps,function(a,b){y(b,!0)});
p.append(e);
k.append(n);
b.append(p);
b.append(k);
c.includeFinishButton&&k.append(s);
k.append(q).append(r);
How about using the attr() function like you use for defining a href:
$('#yourButton').attr('name', 'yourName');
To create a button on the fly:
var btn = $('<button/>').attr('name', 'next').addClass('btn btn-success pull-right');
Which results in the following HTML:
<button class="btn btn-success pull-right" name="next"></button>
I'm beginning with jQuery and using it with twig/Symfony 2.
I have a little problem : when I use this in a loop :
<a href="#" id="dialog_link"><button type="button" id="button_id" id-uservalue="{{user.id}}" class="btn btn-danger btn-xs">
Delete
</button></a>
Only the 1st Button works, the other just dont. I checked the value of {{user.id}} it changes.
This is the jQuery code :
click : function() {
var id_user = $('#button_id').attr('id-uservalue');
Thanks a lot, internet friends !
Since id is unique, you need to use class instead:
<a href="#" id="dialog_link"><button type="button" class="button_id" id-uservalue="{{user.id}}" class="btn btn-danger btn-xs">
then you can use:
click : function() {
var id_user = $(this).attr('id-uservalue');