I have an app where a user is able to delete another user. When the user clicks the delete button, a pop-up window appears asking the user if they are sure they want to take this action. When the user clicks confirm, I'd like the user to be deleted.
I achieved this initially before by putting a remove method on the button, like this:
<button ion-button (click)="remove(i);">Delete</button>
And in my .ts I had this code:
this.items = [
{user: 'UserA'},
{user: 'UserB'}
];
remove(no) {
(this.items).splice(no, 1);
}
My problem is that now, when the user clicks the button, the method top open the popup is called:
<button ion-button (click)="showConfirmAlert();">Delete</button>
And I'm not sure now how to remove the item from the list.
showConfirmAlert() {
let alert = this.alertCtrl.create({
title: 'Confirm delete user',
message: 'Are you sure you want to permanently delete this user?',
buttons: [
{
text: 'No',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Yes',
handler: () => {
}
}
]
})
}
Do I need to write a separate remove function, inside the showConfirmAlert method? How do I go about doing this? Sorry, very new here, any help would be really appreciated!
In your html file:
<button ion-button (click)="showConfirmAlert(i);">Delete</button>
In your ts file:
showConfirmAlert(i) {
let alert = this.alertCtrl.create({
title: 'Confirm delete user',
message: 'Are you sure you want to permanently delete this user?',
buttons: [
{
text: 'No',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Yes',
handler: () => {
this.items.splice(i,1);
}
}
]
})
}
Related
enter image description here
I'm using Select in Ant Design and don't know how to remove this icon.
Does anyone know the solution?
I try to edit some css and try config provider also but nothing work. Maybe i don't know the right way to do it
Hope you guys can help me
You can pass null to suffix prop in Select Component.
import { Select } from 'antd';
const App = () => {
return (
<Select
style={{ width: '200px' }}
suffixIcon={null}
options={[
{ value: '1', label: '1' },
{ value: '2', label: '2' }
]}
/>
);
};
export default App;
I am using react-hook-form with material-ui checkboxes. The following code works fine; however, each checkbox gets bound to its own field. In partial, when I hit submit, the output is something like this: {option1: true, option2: undefined, option3: true}
What I am hoping for is to get the output from all three checkboxes to bind into a single array, i.e. for the output to be something like this: {checkboxFieldName: [option1, option3]}.
I know that when using Formik, this is possible when the FormControlLabels of all checkboxes have the same names. So, just wondering if something similar is possible with react-hook-form.
Thank you in advance.
const options = [
{ key: 'option1', label: 'Option 1', val: 'option1' },
{ key: 'option2', label: 'Option 2', val: 'option2' },
{ key: 'option3', label: 'Option 3', val: 'option3' },
]
function App() {
const { handleSubmit, control } = useForm();
const onSubmit = data => console.log(data);
return (
<form onSubmit={handleSubmit(onSubmit)}>
<FormControl>
<FormLabel>Check all suitable options</FormLabel>
<FormGroup>
{options.map((option) => (
<FormControlLabel
key={option.key}
name='checkboxFieldName'
value={option.val}
control={
<Controller
control={control}
name={option.key}
render={({ field: { onChange, value }}) => (
<Checkbox
checked={value}
onChange={e => onChange(e.target.checked)}
/>)}
/>}
label={option.label}
/>)
)}
</FormGroup>
</FormControl>
<Button type="submit">Save</Button>
</form>
);
}
I tried to do the same thing with Material UI but I ended up with more problems. Basically, you need to store selected checkboxes somewhere else (within an array) and set them to react-hook-form's state by using setValue function: https://react-hook-form.com/api/useform/setvalue/
Example: https://blog.logrocket.com/using-material-ui-with-react-hook-form/
If you don't want to do it manually, I would suggest using react-spectrum. It has a CheckboxGroup component and it stores all the selected values in an array: https://react-spectrum.adobe.com/react-spectrum/CheckboxGroup.html
Another solution is that you don't try to convert material-ui's object (checkboxFieldName: {option1: true, option2: undefined, option3: true}) into an array ({checkboxFieldName: [option1, option3]}) before submitting. Once you submit your form, you can convert your checkboxFieldName object into an array before passing the data to an API. Such as:
let checkboxFieldName = {option1: true, option2: undefined, option3: true}
let redefinedCheckboxFieldName = []
Object.entries(checkboxFieldName).forEach(([key, value]) => {
if(value){
redefinedCheckboxFieldName.push(key)
}
})
I can't seem to detect a button press in cakephp4. In cake3 it was easy.
In Form I have:
echo $this->Form->button('View Data', [
'name' => 'viewdata',
'type' => 'submit',
'class' => 'btn btn-primary'
]);
In Controller I have:
if ($this->request->is('post') ) {
....
debug($this->request->getDdata());
if (!empty($this->request->getData('viewdata'))) {
I click the button and I see 'viewdata'='' so it detects the button has been clicked but its made the value = null? and I can't invoke the button press function of viewdata.
https://book.cakephp.org/4/en/views/helpers/form.html#creating-buttons-and-submit-elements
The value is not null, it's an empty string. So you could for example do a strict check for that exact value, ie:
if ($this->request->getData('viewdata') === '') {
// view data submit button was used
}
Or just check for the keys existence by comparing against null:
if ($this->request->getData('viewdata') !== null) {
// view data submit button was used
}
I am trying to add a drop down to CKEditor's link dialog. When selected, the drop down should insert corresponding class name to the link.
CKEDITOR.on( 'dialogDefinition', function( ev ) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if ( dialogName == 'link' ) {
var infoTab = dialogDefinition.getContents( 'info' );
infoTab.add({
type: 'select',
label: 'Display link as a button',
id: 'buttonType',
'default': '',
items: [
['- Not button -', ''],
['Button one', 'btn-primary'],
['Button two', 'btn-success'],
['Button three', 'btn-danger']
],
commit: function(data) {
data.className = this.getValue();
}
});
}
});
I have a feeling commit function is not doing the job, but cannot figure out how to make it work. I saw a code that almost does the same thing as I want at http://www.lxg.de/code/simplify-ckeditors-link-dialog. I tried it and it does not work either.
I am using CKEditor 4.3.2.
I appreciate your help in advance.
If you console.log the data object in link dialog's onOk, you'll find quite a different hierarchy. Element classes are in data.advanced.advCSSClasses. But even if you decide to override (or extend) the value of this property in your commit, your string will be nuked by the original commit of advCSSClasses input field ("Advanced" tab) anyway. So the approach got to be a little bit different:
Always store the value of the select in data.
Override commit of advCSSClasses input field to consider stored value.
Remember to execute the original commit of advCSSClasses input.
Here we go:
CKEDITOR.on( 'dialogDefinition', function( ev ) {
var dialogName = ev.data.name;
var dialogDefinition = ev.data.definition;
if ( dialogName == 'link' ) {
var infoTab = dialogDefinition.getContents( 'info' ),
advTab = dialogDefinition.getContents( 'advanced' ),
advCSSClasses = advTab.get( 'advCSSClasses' );
infoTab.add( {
type: 'select',
label: 'Display link as a button',
id: 'buttonType',
'default': '',
items: [
['- Not button -', ''],
['Button one', 'btn-primary'],
['Button two', 'btn-success'],
['Button three', 'btn-danger']
],
commit: function( data ) {
data.buttonType = this.getValue();
}
});
var orgAdvCSSClassesCommit = advCSSClasses.commit;
advCSSClasses.commit = function( data ) {
orgAdvCSSClassesCommit.apply( this, arguments );
if ( data.buttonType && data.advanced.advCSSClasses.indexOf( data.buttonType ) == -1 )
data.advanced.advCSSClasses += ' ' + data.buttonType;
};
}
});
Now you got to only write a setup function which will detect whether one of your button classes is present to set a proper value of your select field once the dialog is open.
I'm building a Zend Application using doctrine repository classes to update, delete and insert data to the DB. These repositories are called from controller actions and they do exactly what they supposed to do. However, I'd like to add some confirmation dialogs to the application, so for example, if a user wants to edit or delete an item, a Confirm Edit or Delete dialog must first be opened and the data will be edited or deleted depending on what the user selects. Here's an example of some action code for updating a staff members details after the user has clicked on a zend form submit button.
public function updatestaffAction()
{
if ($this->getRequest()->isPost()) {
if ($form->isValid($this->getRequest()->getPost())) {
$values = $form->getValues();
$user = $this->entityManager->find('\PTS\Entity\Staff', $values['staff_number']);
$staffValues = array('staff_number' => $values['staff_number'],
'title' => $values['title'],
'first_name' => $values['first_name'],
'last_name' => $values['last_name'],
'telephone' => $values['telephone'],
'cellphone' => $values['cellphone'],
'fax' => $values['fax'],
'email' => $values['email'],
'job_title' => $values['job_title']);
$this->staffRepository->saveStaff($staffValues);
$this->entityManager->flush();
}
}
The staff repository saveStaff method simply creates a new Staff object and persists that object if the staff member doesn't exists, or merges the new data if it's an existing staff member as is the case for the update code above.
So my question is, how can I change the action to only save the data once the user has clicked the yes button in a confirmation dialog. BTW, the dialog can be either a JQuery or Dojo dialog box.
When you create form's submit button, set js code:
$submit = new Zend_Form_Element_Submit('delete');
$submit->setAttrib(
'onclick',
'if (confirm("Are you sure?")) { document.form.submit(); } return false;'
);
Or, if you want to set dialogbox on link (if you don't have submit form):
onclick="if (confirm('Are you sure?')) { document.location = this.href; } return false;"
Code for showDialog:
$(function() {
$( "#dialog:ui-dialog" ).dialog( "destroy" );
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Are you sure": function() {
// PUT your code for OK button, for eg.
document.form.submit();
$( this ).dialog( "close" );
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
});`
Thx, I used the second option like this way :
Delete
and it's worked :)