0

add prefixed text to textfield linked to multiple choice

Hi,

Brief intro: my name is Brit and I have founded a charity to give people with physical disabilities in The Gambia mobility.
I use Ninox for client registration, assessment and mobility aids needed.

Am often out in the field without internet and use the Ninox app on my phone. I've managed to create a database with a layout that works well on my phone but have 2 issues I would appreciate if anyone can help.

1

I use multiple choice for 'equipment' (see image)
For 'wheelchair regular', 'wheelchair full support' and 'child walker' during assessments measurements need to be noted (different for each equipment). I would want a textfield to show up with predefined text so only the measurements need to be added.
For example if 'wheelchair regular' is chosen it would show a text field with predefined text as below where I can add measurements after A, B, C, D
A hip B. up.leg C. un.leg D. back 
A
B
C
D

I've created a textfield linked to the multiple choice options but can't manage to add the prefixed text. I've also tried with a button, but can't manage to get just the button to show up and the text field only when button is clicked.

2

DOB on my phone in the mobile app I can only use the calendar (with is not useful) and not type the DOB. Can't risk loosing all the data, any options?

Help much appreciated, thanks!

21 replies

null
    • Fred
    • 6 mths ago
    • Reported - view

    what is the code in your button?

    I don't think you need to worry about displaying/hiding the button. Once the code works you can put the code in the Trigger after update of the multiple choice field. then you can get rid of the button.

    What are the field names that you are working with?

    For the DOB, you can use a text field that has code in the Trigger after update that then sets the date field.

      • caring4mobility
      • Brigitte_Honsbeek
      • 6 mths ago
      • Reported - view

       thanks for your help.

      Hope this (and the picture) answers your questions? When I check 'wheelchair regular' the button and textfield show up, but only if I click the button the predefined text will show. 

      On click:

      let textToAdd := "A hip
      B up leg
      C un leg
      D back";
      'Measurements regular wheelchair' := textToAdd

      In regards to DOB if I set it to textfield will I loose previously entered data? The DOB field is also linked to 2 other fields that calculate Age and Age group (child, adult, senior)

    • Fred
    • 6 mths ago
    • Reported - view
     said:
    When I check 'wheelchair regular' the button and textfield show up, but only if I click the button the predefined text will show. 

     So you got this part to work. That is great.

    You can modify your code to:

    var CRLF := urlDecode("%0D%0A");
    let textToAdd := "A
    B
    C
    D";
    Measurements := if length(Measurements) != 0 then
            Measurements + CRLF
        end +
        textToAdd
    

    Line 1, creates a variable to insert a carriage return or line feed. I use this in place of hard coding a carriage return which can make reading the code harder.

    Lines 2 - 5, you know. You could replace all the carriage returns with CRLF so it all fits on 1 line.

    Lines 6 - 9, adds a bit of logic to make sure you don't overwrite any text that is already in the Measurements field. So it adds a if statement to check the length of field Measurements and if it is NOT equal to zero then we add the contents of Measurements plus the variable CRLF then the added text variable.

    Now on to your Display only if part of the button and text field.

    You are using a multiple choice field so you can not just use a simple equal sign when searching the selections.

    What is happening is Ninox creates an array of choices when you select more than 1 choice. If you open your multiple choice field you will see numbers next to each choice. Now if you create a new formula field and put it next to your multichoice field and put this in it:

    numbers(Equipment)
    

    and as you select choices you will see this field show all of numbers of the choices you select/deselect.

    So how do you search for multiple selections? Well it would look something like:

    let validEquipCode := [1, 2];
    let xEquip := numbers(Equipment);
    count(xEquip[var e := this;
                count(validEquipCode[= e]) > 0]) > 0
    

    Line 1, creates an array of choice numbers that you want the button to appear. You can reference your multichoice field to verify the choice numbers and replace the ones you want.

    Line 2, makes an array of all of selection in the Equipment field

    Lines 3 & 4, is the code that takes each selection from the Equipment field and checks if it exists (using the count() command) in the validEquipCode and if 1 or more of the numbers is returned then it will show the button.

    Now the button will show/hide on multiple possible choices.

    I'll let you digest this for now.

    When you have a moment, take a look at my comments about relational DBs:

    https://forum.ninox.com/t/y4ym8g8?r=x2ym8dz

    • Fred
    • 6 mths ago
    • Reported - view
     said:
    In regards to DOB if I set it to textfield will I loose previously entered data? The DOB field is also linked to 2 other fields that calculate Age and Age group (child, adult, senior)

    I was not suggesting removing the DOB field. You would be adding a new field, let us call it 'EnterDate', then after you enter it it will update the DOB field with whatever data you enter.

    Add a new text field, call it EnterDate, and another button then put this in the On click:

    let step1 := split(EnterDate, "/");
    let xDay := number(item(step1, 0));
    let xMon := number(item(step1, 1));
    let xYear := number(item(step1, 2));
    DOB := date(xYear, xMon, xDay)
    

    When you enter the date, it is assuming you will use a slash (/) between date data, i.e. day/month/year. It is also expecting a four digit year. If you don't use a slash then replace the slash in line 1. Do not use any other separator.

    Line 1, converts the data from the EnterDate field into an array. Arrays are your friend.

    Line 2, gets the data for day using the item() command and then converts is back into a number with the number() command

    Line 3, gets the data for month using the item() command and then converts is back into a number with the number() command

    Line 4, gets the data for year using the item() command and then converts is back into a number with the number() command

    Line 5, sets the DOB date field using the date() command.

    If everything works like you expect, then copy the code from the button to the Trigger after update of EnterDate and now when you enter the data then click out the DOB field will be updated.

      • caring4mobility
      • Brigitte_Honsbeek
      • 6 mths ago
      • Reported - view

       thank you so much for the reply and more so for also explaining so I can actually try to understand and learn!

      There's one hiccup, you used xYear XMon X Day which is exactly what I but it doesn't show up like that in the DOB field.
      I tried Show as 

      format(DOB, "DD.MM.YYYY")

      But to no avail.

      One additional question: can I hide the button?

      • Fred
      • 6 mths ago
      • Reported - view

      Yeah, Ninox has some issues with showing Date in the correct format. Is your phone set to your locale? Does other date in your phone show the correct format? I have no idea what the Show As part does in the Date field does.

      The button is yours to show/hide whenever you want. You are the DB owner.

      • caring4mobility
      • Brigitte_Honsbeek
      • 6 mths ago
      • Reported - view

       that's a terrible issue! Can't use the app on my phone atm so am working on my laptop. Waiting on support to solve the issue on the phone app (data migration required). Bit stressed as Im doing field work this week and need the app for that.

      Regarding the button: I would like to hide it in my layout as it has no function there.

      • Fred
      • 6 mths ago
      • Reported - view
       said:
      Regarding the button: I would like to hide it in my layout as it has no function there.

      Well what are the parameters to show/hide the button.

      • caring4mobility
      • Brigitte_Honsbeek
      • 6 mths ago
      • Reported - view

       I got it wrong. 

      If I now check for example 'regular wheelchair' it will show the button and the empty text field.
      I then need to click the button first to show the text in the field.
      What I actually want is for the text field to only show up if the button is clicked and with the predefined text.

      I'm learning...

      • caring4mobility
      • Brigitte_Honsbeek
      • 6 mths ago
      • Reported - view

       the DOB Entry button does not need to be visible at any time as the Enter DOB field is visible

    • Fred
    • 6 mths ago
    • Reported - view
     said:
    What I actually want is for the text field to only show up if the button is clicked and with the predefined text.

    To do this you need another field that tracks the show/hide status. You can make it a number field, then add the code to your button:

    newNumberField := 1
    

    Then in the Display only if of the Measurements field you would add:

    newNumberField = 1
    

    You can set the Display on if of the new field to be null then it will not show.

      • caring4mobility
      • Brigitte_Honsbeek
      • 6 mths ago
      • Reported - view

       getting there but still the predefined text isn't showing up?

      • Fred
      • 6 mths ago
      • Reported - view

      does the button work?

      • caring4mobility
      • Brigitte_Honsbeek
      • 6 mths ago
      • Reported - view

       yes the button works

      • Fred
      • 6 mths ago
      • Reported - view

      just to be sure, the button adds the text you want?

      so what is the issue?

      • caring4mobility
      • Brigitte_Honsbeek
      • 6 mths ago
      • Reported - view

       if I check 'regular wheelchair' both the button and the empty field show up. I then have to click the button to make the text show up.

      I would like just the button to show up and if clicked the text field but with predefined text 

      • Fred
      • 6 mths ago
      • Reported - view

      then follow my post above.

      • caring4mobility
      • Brigitte_Honsbeek
      • 6 mths ago
      • Reported - view

       I have followed your post, maybe I'm missing something?

      This is the on click in the button

      var CRLF := urlDecode("%0D%0A");
      let textToAdd := "A hip
      B up.leg
      C un.leg
      D back";
      'Measurements regular wheelchair' := if length('Measurements regular wheelchair') != 0 then
              'Measurements regular wheelchair' + CRLF
          end +
          textToAdd

      • Fred
      • 6 mths ago
      • Reported - view

      I can see this post has gotten confusing about what goes where. The Button 'Display field only, if' should not be based on NumberFieldRW since the button modifies the field. Check out this reply for the correct code for the 'Display only if'.

    • Fred
    • 6 mths ago
    • Reported - view
     said:
    the DOB Entry button does not need to be visible at any time as the Enter DOB field is visible

    You can modify the Display only if or move the button to a tab.

      • caring4mobility
      • Brigitte_Honsbeek
      • 6 mths ago
      • Reported - view

       just figured hiding the button thanks to your other reply :)

Content aside

  • 6 mths agoLast active
  • 21Replies
  • 61Views
  • 2 Following