Set an option to some prompt fields to get them active as a button

Hi, just a message to suggest it would be useful for the addSegmentedControl prompt field (and maybe also the addSwitch and addSelect fields) to be optionaly active as a button.

Here’s the use case. In a few scripts, I use prompts with addSegmentedControl and addSelect fields. The addSegmentedControl field is obviously used to select a value, but not only : the items of the addSelect field depends also on the addSegmentedControl value. When I change this value and press the button, I get a new prompt with the corresponding items in addSelect ; when I don’t change the value, the prompt returns all the selected field values.

Prompts are showed in a loop until the addSegmentedControl value is not changed.

let p,
  controls = ['one', 'two', 'three'], 
  control = 'one',
  items = {
      'one':['a', 'b', 'c'], 
      'two':['d', 'e', 'f'], 
      'three':['g', 'h', 'i']
    };
while (true) {
  p = Prompt.create();
  p.addSegmentedControl('control', '', controls, control);
  p.addSelect('item', '', items[control], [items[control][0]]);
  p.addButton('OKAY');
  let didSelect = p.show();
  if (!didSelect) {
    break;
  }
  if (p.fieldValues['control'] == control) {
    break;
  }
  else {
    control = p.fieldValues['control'];
  }
}
alert(p.fieldValues['item']);

I wonder if it would be possible and worth to get the same result just by changing the value of the addSegmentedControl field, acting thus as a button. It would then not be requested to press a button and it would thus go faster and would be more convenient in certain cases.

I hope my message is clear. Please ask me if you have questions.

I guess I don’t quite follow the use case here, but why use a segmented control at all? Why not just use buttons if you want them to trigger actions?

Yes sorry, I admit the example I gave is not a great one because simple buttons would do the trick.

Here’s a screenshot with one of several prompts I have.

I first used buttons, but with time, I added some more buttons and some items (in the Actions list). It’s a bunch of elements on a tiny screen, so in order to regroup elements, save place and reduce scrolling, I replaced buttons by segmented controls (eleven in the red circle).

A lot going on there…regardless, a segmented control is not a button, and I would not change it’s standard behavior.

I think you are saying the select is only necessary if a change is made to the segmented control? In which case, I’d tend to suggest you move it to a different prompt entirely, that only appears if the conditions are met in the first prompt.

You may be getting into a custom enough set of UI requirements that you would be better of building an HTML form to interact with, that could have the logic built into it to hide/show/require elements.

Controls are categories of actions and the prompt allows me to choose a category AND a related action (and other elements) with the less taps possible.

I understand your position regarding the standard behavior of segmented controls. And I know I certainly use Drafts beyond its standard use.

I’ll look then around html forms. Thanks :slight_smile:

I explored the html preview forms. I’m afraid it won’t do it for me.

The standard prompts I call are generated on the fly, gathering data from some drafts. The data is gathered only from the needed draft(s). For instance, when I first launch the prompt with control “XXX” as a value for the segmented control field, the script fetches and caches items from the draft “XXX” only (which I can edit besides wherever and whenever I need) ; if I select an item, I can process the result and it’s done. But when I choose another control, for instance “YYY”, the script in the “while” loop then fetches and caches items from the draft “YYY”. And so on and so forth. The result is instant, no delay, no need of useless data. Performance is optimal.

I tried a first test with html preview and there’s a short but perceptible delay each time I show the preview in the “while” loop. This delay is annoying to me because I use the prompt very very often each day. I could get rid of the loop and gather data once from all the drafts corresponding to the controls, masking the items I don’t need, but performance would be degraded too in this case because I would then have to find and get all the drafts and their content (which can be huge).

As always, I guess it’s a question of balance between constraints and I think I will keep my system as it is, for now, because it is highly satisfactory to me thanks to the so powerful Drafts features.

But just another suggestion, if I may. I understand the segmented control is not a button and will stay as it is. But if one day, it’s possible to get a button bar that looks like segmented control and that can be inserted wherever in the prompt, it would be awesome.