cordova-plugin-actionsheet icon indicating copy to clipboard operation
cordova-plugin-actionsheet copied to clipboard

Return the selected button value along with the button index

Open Beagle25 opened this issue 10 years ago • 6 comments

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!

Beagle25 avatar Sep 27 '14 19:09 Beagle25

+1 Can it be done now? Thanks!

fernandopg avatar Feb 17 '15 17:02 fernandopg

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.

EddyVerbruggen avatar Feb 17 '15 17:02 EddyVerbruggen

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!

fernandopg avatar Feb 17 '15 19:02 fernandopg

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?

EddyVerbruggen avatar Feb 17 '15 19:02 EddyVerbruggen

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 avatar Feb 17 '15 20:02 fernandopg

@fernandopg Have you figured out a way to deal with dynamic loaded labels? I have the exact same problem as you describe

sjosen avatar Aug 05 '16 20:08 sjosen