change the default confirm button in bootbox and yii2 - yii2

I'm using bootbox.js along with yii2 framework to change the default confirmation popup on delete actions.
When I hit the "delete" buttons the bootbox popup appear properly but the "ok" button is preselected, so if the user hit the "enter" button the action take place.
Is it possible to change the default selected button from "ok" to "cancel"?
Thank you

There isn't anything baked into the library to do what you want, but something like this should work:
var dialog = bootbox.confirm("Please confirm action", function(result){
/* handle result */
});
dialog.on("shown.bs.modal", function() {
dialog.find('.modal-footer .btn.btn-default').focus();
});

Related

How to not allow user to enable input editing [duplicate]

I have a button as follows:
<input type="submit" class="button" value="FooBar" name="FooBar" id="FooBar" disabled="disabled">
I am enabling this button only when certain parameters are met. To test whether it was secure, I pressed F12 (or right click -> Inspect Element) and edited out the text disabled="disabled". Doing this overrides my code and that is scary. How can I prevent someone from changing it in this manner?
I am using php and jquery in this page and using the latter to enable or disable the button. I have checked the jquery click function and it not only executes, but shows the button as not disabled. The alert below reads Disabled: false
$("#FooBar").click(function(){
alert('Disabled: ' + $(this).is('[disabled=disabled]'));
})
So how can I prevent a user from changing the button disabled state and thus overriding my logic?
You can disable the right-click by doing:
document.addEventListener('contextmenu', event => event.preventDefault());
but it is not recommended. Why? It achieves nothing other than the annoying user
OR
Alternatively, a better approach is to recheck your validations in submit action and simply returns if it fails, in this case, if user inspects and changed the state of a button, the button stays idle and will not allow to proceed
$("#FooBar").click(function() {
if (!this.acceptenceCriteria()) {
return;
}
alert('Disabled: ' + $(this).is('[disabled=disabled]'));
})
You can't stop people from using dev tools.
You can try a couple of tricks to disable right clicking (like the one below) which will stop some number of people but ultimately the solution to your problem is to use html and http properly.
$(document).bind("contextmenu",function(e) {
e.preventDefault();
});

Change background color of button after sent action (after one click)

Hello I have a contact form I want to do it with PHP. And I have the submit button, I want when all fields are ready to press, when the email was send to change my button. First in my button is a text with background color yellow and the text is "Send". When I press the button and the email is sent I want to change the background color in red and I want to add an icon aside to text, the text is modifed in "Sent". How can I do this?
<script src="jquery.min.js"></script>
<script >
function button(){
//your ajax code for sending data
/* function retrieveData(){
$.post('server.php',{}, function(data){
});*/
$("#button").attr('value', 'Sent');
$("#button").css("background-color","red")
}
</script>
<input type="button" id="button" name="button" value="Send" onclick="button()">
Try this. You can do it with javascript.
You have a form with some inputs and a submit button.
You want to manipulate the submit button after all of the form fields were filled-in, and finally manipulate it again once the submit button was clicked.
What you need to do is to write a little javascript (either plain vanilla or jQuery, choose what suits you best) to handle two things in your form
Your form's input fields (for first submit button change):
Attach an event to the input fields to check for validation as you wish, and change the submit button accordingly.
Your form's submit button (for the second submit button change):
Attach a click event to the submit button (and make sure to prevent the default, so once the submit button was clicked, it will be manipulated in the way you wish.
I have wrote you an example, where in my scenario I have two input in my form and a submit button which is disabled and greyed-out by default.
As soon as all form fields are filled-in (not empty), the submit button becomes active (disable attribute removed and color change) - finally when the submit button is being clicked, it will change it's color to green as an indication that it was clicked.
$('#myForm input').on('keyup',function(){
var validated = true;
$('#myForm input').each(function(){
if($(this).val() === ''){
validated = false;
}
});
if(validated){
$('#submitBtn').removeClass('disabled').prop('disabled',false);
}else{
$('#submitBtn').addClass('disabled').prop('disabled',true);
}
});
$('#submitBtn').on('click',function(e){
e.preventDefault();
e.stopImmediatePropagation();
$(this).addClass('submited').prop('disabled',true);
// the rest of your code for submission..
});
Here's the simple fully working example:
https://jsfiddle.net/wx9gonrh/
Of course you can use this example and modify it to your own needs, or write your own from scratch using this as guidance.
In your case you might want to incorporate an async method for changing the submit button only after the emails were successfully sent (e.g. an ajax complete\done event)
Hope it helps!

Yii2 to make a button disappear after clicked

I want to make a report button that a user can click only once. After clicking it will disappear and show a text saying "Already Reported" instead.
Can someone help me with this?
you can use jquery. Add a class "yourclass" to your button and add following script to your js file
$(document).ready(function(){
$(document).on('click', '.yourclass', function(){
$(this).after("Already Reported");
$(this).remove();
});
});

how to remove "X" button from popup in angularJS

How can I remove "X" button from Popup in angularJS? I don't need it because the cancel button that I have implemented has same functional but the "X" button couldn't reset modifies. It will be implemented as default in HTML:
<div class="ngdialog-close"></div>
While opening popup you need to pass one option showClose which will hide close button if its false.(default true)
Code
ngDialog.open({
template: 'templateId',
className: 'ngdialog-theme-default',
showClose: false //<-- while opening dialog make it false
});
You have to read documentation before integrating (using) any module in your project. Here is the complete list of options for ngDialog.
Hide close button

Generate Href target blank link from popup form

I want users to input some url in a text field from a popup, and then, when submit the popup the parent page auto refresh and shows the url they have insert, with hyperlink to the site.
I have now set a scrypt to store the form in a cookie, that computer can read everytime users come back to the site.
You can see my work in: http://www.resmasecamadas.com/test
You can achieve it using JS. you dont need to use cookies at all!
Observe this sample code.
//On click of this button new Popup will be opened!
<button onclick="myFunction();">Open popup</button>
<script>
function myFunction() {
var popup = window.open("", "popup", "width=200, height=100");
popup.document.write("<input type='text' name='text' id='text'><button onclick='window.opener.passFunction(text.value);'>click</button>");
}
function passFunction(x){
document.write(x);
}
</script>
You can send data from pop up window using window.opener.someFunction(parameters)here "someFunction" is a function in parent window!