cordova-plugin-actionsheet
cordova-plugin-actionsheet copied to clipboard
Return the selected button value along with the button index
Could you please alter the show() callback to return both the selected button value and button index?
This would help out tremendously when dealing with dynamically generated action sheets.
Thank you!
+1 Can it be done now? Thanks!
I'm not sure why you need it exactly - you should be able to track the indexes and values in javascript as well.
Also, adding the value to the callback would break current usage.
It helps you when you create the action sheets dynamically and you don't know how much options you have nor the index for each option.
Another option could be if you can assign manually the index number for each option!
Can you show me an example of a dynamically created actionsheet where it's not possible to remember which item was added in which order?
Of course @EddyVerbruggen , here I have an example with a user that can do different things if is owner of the table or not, and depends of a table status also. I don't say that it is impossible to know the order in case of dynamic created actionsheet but I think that helps you a lot if you can read the button value or if each option has a defined index and the order doesn't matter.
var buttonsLabel = ['View'];
// if owner
if (user.id === table.owner) {
switch (table.status) {
case 'new':
buttonsLabel.push('Delete');
break;
case 'edited':
buttonsLabel.push('Copy', 'Delete', 'Save');
break;
case 'deleted':
buttonsLabel.push('Restore', 'Delete forever');
break;
}
if (status === 2) {
buttonsLabel.push('View');
}
// not owner
} else {
switch (table.permissions) {
case 'read':
buttonsLabel.push('Copy');
break;
case 'write':
buttonsLabel.push('Delete', 'Save');
break;
}
}
window.plugins.actionsheet.show({
'title': "Actions",
'buttonLabels': buttonsLabel,
'androidEnableCancelButton' : true,
'addCancelButtonWithLabel': 'Cancel'
}, _.bind(this.onActionSheet, this));
Anyway, if is not possible no problem! The plugin is awesome and I can workaround that without problem!
Thanks and sorry for my bad English... ;-)
@fernandopg Have you figured out a way to deal with dynamic loaded labels? I have the exact same problem as you describe