6 Replies Latest reply on Apr 7, 2009 4:41 PM by comment_1

    Entering numerical value from value list

    michno

      Title

      Entering numerical value from value list

      Post

      I have a weird issue that's been bothering me for a while...

       

      I have a field (well several actually) that are set up as Numeric only. In the layout these fields are formatted as checkboxes with a value list that holds just one value: 1. However, when i click the checkbox to set the field value to 1, I get a message that the field only allows numeric values and I need to revert. Apparently you can't input numeric values using a value list?

       

      I've also tried using a script trigger to insert GetAsNumber (1). This also gives me the error message, but this time I can click OK and the field contains the checkmark (=1). Anyone have any ideas as to why?

        • 1. Re: Entering numerical value from value list
          philmodjunk
            

          michno wrote:

          I have a weird issue that's been bothering me for a while...

           

          I have a field (well several actually) that are set up as Numeric only. In the layout these fields are formatted as checkboxes with a value list that holds just one value: 1. However, when i click the checkbox to set the field value to 1, I get a message that the field only allows numeric values and I need to revert. Apparently you can't input numeric values using a value list?

           

          I've also tried using a script trigger to insert GetAsNumber (1). This also gives me the error message, but this time I can click OK and the field contains the checkmark (=1). Anyone have any ideas as to why?


           

          Michno, using FMP 10 adv: I checked out your description above:

          1. I defined a number field and set validation to Strict Data type, numeric only.
          2. I placed the field on a layout, formatted it to use checkboxes, specifying a single value value list: 1.
          3. When I clicked on the check box, everything worked fine. No error messages appeared.
          4. I could only duplicate your report if my value list had more than one value and I clicked a second check box. Since this attempts to store two values separated by a carriage return, as expected the validation message warning me that I was entering non-numeric data appeared.

           

          Compare what I've done to your situation and see if you can identify what's different.


          • 2. Re: Entering numerical value from value list
            michno
              

            Thanks. The problem is (which a forgot to mention) that the field in question (from an external SQL source) is also set to evaluate as Not Empty. If the field already contains 1, clicking the checkbox will remove the value (1) and the field becomes empty. Bad.

            If the field contains 0 (not checked) the value list attempt to add 1 (with carriage return) which also fails.

             

            So, I've tried to create a script trigger that sets the field to 0 when it is 1, and the other way round. This also fails because although I set the trigger to trigger on OnObjectStart the valuelist gets to it first and removes the value if 1 and does its carriage return trick if 0.

             

            • 3. Re: Entering numerical value from value list
              philmodjunk
                

              Hmmm,

               

              I think I'd format the field as a pop up menu with values 0 and 1 in its list, or I'd use radio buttons  with 0 and 1 instead of a single value check box.

               

              Check boxes work best with text fields as they enable the user to input combinations of values, each of which will be separated by carriage returns. In your case, you want to allow the values 1 or 0, not both and you don't want to allow blank values either.

               

              At no time will a value list modify the contents of a field. It controls what is visible and limits how a user interacts with it. What I think is happening is as follows:

               

              Your script trigger assigns 0 to the field. Since you don't have a check box for the value zero, you see a single unchecked check box. If you click the check box, it appends a 1 to the field so that you now have 0 <carriage return> 1, you see the check box as checked, but the validation error pops up due to the carriage return.

               

              Since pop up menus and radio buttons replace field contents instead of appending values, they should do the job for you.

               

              Note: One way to debug issues with check box formatted fields is to temporarily place a second copy of the field next to the original, remove the check box formatting and resize it to be several lines of text tall. Now watch how the field's contents change while you click check boxes.

               

              • 4. Re: Entering numerical value from value list
                michno
                  

                I already have the field as a normal input field next to the checkbox version, and yes, when I click the field (which has a value 1 in it). The input field goes blank (1 is removed) and the trigger is then activated (I have the script debugger running). The script now checks if the field has the value 1. It does not so it sets the field to value 1. In short, the field with value 1 is clicked and the value gets reset to 1.

                 

                If I give the field value 0 (through the input version), clicking the field will have the value list insert 1 and a carriage return and then I get the message box telling me that the field can only have a numeric value.

                • 5. Re: Entering numerical value from value list
                  philmodjunk
                    

                  "If I give the field value 0 (through the input version), clicking the field will have the value list insert 1 and a carriage return and then I get the message box telling me that the field can only have a numeric value."

                   

                  That's exactly what I said is happening.

                   

                  That's why I'm recommending a format change. Use radio buttons set to show both values (0 and 1) or format as a pop-up menu. Then you won't have this problem.

                  • 6. Re: Entering numerical value from value list
                    comment_1
                      

                    You have a timing issue here: the validation kicks in before the script can make the correction.

                     

                    I'd advise you to remove the script trigger, set the field to auto-enter a calculated result (replacing existing data) = GetAsBoolean ( Self ), and change the validation method to' Validated by calculation' = Exact ( GetAsNumber ( Self ) ; Self ).

                     

                    Alternatively, make the field a button that sets the field to = not YourTable::YourField.