0

Choose more than one?

This has turned out to be a day for questions. Here's my next burning question: Is it possible to select more than one item in a Choice field? For example, if I have the items displayed as Radio buttons, can I give the user the option of selecting two of the items and not just one?

Thanks,

Marcia Morrison
in Salem, Massachusetts

9 replies

null
    • Gianluca
    • 1 yr ago
    • Reported - view

    zenmom  

    Hello there,

    maybe I haven't understood correctly what you want to do, but...you can use a multiple choice field for that purpose.

    • Lars
    • 1 yr ago
    • Reported - view

    As Gianluca said, there are multiple choice fields. But be careful, limiting the number of selections that can be made is very difficult. So it's either 1 or as many as possible.

      • Ninox partner
      • RoSoft_Steven.1
      • 1 yr ago
      • Reported - view

      Lars you can limit the # of selected choices in a multiple choice.

      • Lars
      • 1 yr ago
      • Reported - view

      RoSoft_Steven Rooryck Thanks for the hint - I checked that and didn't find anything in the configuration of the field. I guess you can manually (script) limit the number, but that is what I'd call very difficult. Can you please tell me, how to limit the number of selected choices?

      • John_Halls
      • 1 yr ago
      • Reported - view

      Lars Hi, I'm in the middle of working this out for you. As you say, it's not simple. I should have a solution for you before the end of the weekend!

      • Ninox partner
      • RoSoft_Steven.1
      • 1 yr ago
      • Reported - view

      John Halls Lars It is actually not that difficult. If you want to limit the choices to 2 you can add this in the Writable if setting of the multiple choice field: cnt(chosen('M ChoiceField')) < 2

      You also need a button to clear the selections if you've reached the limit as you can't change selections in the MCFielf anymore : MChoiceField := 0

      https://forum.ninox.com/t/p8hrt87

      https://forum.ninox.com/t/p8hrth0

      https://forum.ninox.com/t/g9hrzlf/filling-lines-of-ordersarticles-with-dynamic-multiple-choice-fields-and-cascading-dynamic-choice-fields

      Are some treads about multiple choice fields.

      Steven

      • John_Halls
      • 1 yr ago
      • Reported - view

      RoSoft_Steven Rooryck Lars

      I had in mind a Trigger on update: on the MCF that would only allow 2 choices and any attempt to add a third would revert the MCF to its original value. Only when one or both of the two are removed can alternative choices be made.

      This solution requires a text field to store the current hex value of the MCF.

      Thanks to Alain Fontaine for his excellent explanation of how the hex value of a MCF is calculated here  https://forum.ninox.com/t/83hrts2

      I have added a text field and called it MultipleChoiceHexValue, and in the Trigger on update: of your MCF put this code

      let MULTIARRAY := numbers(MultipleChoiceField);
      if count(MULTIARRAY) > 2 then
          MultipleChoiceField := MultipleChoiceHexValue
      else
          let BLOCKCOUNT := floor((max(MULTIARRAY) - 0.5) / 4) + 1;
          let HEXKEY := "0123456789ABCDEF";
          let hexString := "";
          for blockCounter in range(0, BLOCKCOUNT) do
              let hexBlock := 0;
              for blockPosition in range(1, 5) do
                  for multiCounter in range(0, count(MULTIARRAY)) do
                      if item(MULTIARRAY, multiCounter) = blockCounter * 4 + blockPosition then
                          hexBlock := hexBlock + pow(2, blockPosition - 1)
                      end
                  end
              end;
              hexString := hexString + substr(HEXKEY, hexBlock, 1)
          end;
          MultipleChoiceHexValue := hexString
      end
      

      Regards John

      • John_Halls
      • 1 yr ago
      • Reported - view

      Having just posted the above after a few hours working the code out, I thought I'd read all of that post and now realise that my code can be replace with

      if count(numbers(MultipleChoiceField)) > 2 then
          MultipleChoiceField := MultipleChoiceHexValue
      else
          MultipleChoiceHexValue := raw(MultipleChoiceField)
      end
      

      Still, I enjoyed the challenge...

      • Alain_Fontaine
      • 1 yr ago
      • Reported - view

      John Halls Not a one-liner yet, but close 🙂.

Content aside

  • 1 yr agoLast active
  • 9Replies
  • 204Views
  • 5 Following