0

I have a gallery control in a power apps canvas application. which looks like this:

Gallery Design

and the items which I am passing to this gallery is a collection as follows:

Collect(
    QAInputCollection,
    {
        srNo: 1,
        Question: "What is your name?"
        
    },
    {
        srNo: 2,
        Question: "what is your date of birth"
    },
    {
        srNo: 3,
        Question: "What is your age?"        
    }
);

Now the solution for the scenario I am looking for is, If someone adds the value in 2nd field (What is your date of birth?) for example 1 Jan 2000, Then the Age should get calculated automatically till today's date and should be displayed in the third field "What is your age?" and make it disabled so that user cannot edit that field.

Main purpose of this question is to disable a dependent control which located in the gallery control...here age is a dependent control

Is this possible with gallery control? please help!

ajinkya
  • 334
  • 3
  • 15

1 Answers1

0

A formula like the below could compute age from an input like "1987 12 24". You would have to develop this further with Switch() to allow for textual month input:

DateDiff(Date(First(Split(TextInput1.Text," ")).Value,Last(FirstN(Split(TextInput1.Text," "),2)).Value,Last(Split(TextInput1.Text," ")).Value),Today(),TimeUnit.Years)

However, I must point out that your design is not the best UX:

  1. Having to input birth date and age is redundant. If you store the age as a static value, it could also result in errors.

  2. For asking a date input, it is best to use a datepicker control as it already enforces valid dates. To a text input you could input 35th of May and face an error.

mmikesy90
  • 783
  • 1
  • 4
  • 11
  • I just used that for practice purpose, I am not developing something but no problem about pointing. – ajinkya Apr 04 '23 at 08:52