3

I'm working on a Roku app and we want the user's date of birth. Trying not to get too complex on the parsing end (so would prefer to not just have a text box where the user can enter whatever they want). I looked into using a roPinEntryDialog, but that unfortunately I think is only meant for entering payment information. I see that roDateTime is a thing, but that seems to only get the current date, and not have any types of inputs for it.

Any ideas or help?

Thanks!

Cassidy
  • 3,328
  • 5
  • 39
  • 76
  • 1
    i suggest posting the question in Roku's own dev. forum (https://forums.roku.com/viewforum.php?f=34) too, to increase the chance of attention/answer – Nas Banov Jun 11 '17 at 16:43
  • @NasBanov thanks, will do – Cassidy Jun 12 '17 at 16:15
  • 2
    I had the same need and ended up implementing the suggestion that @nas-banov mentioned above, using 3 parallel LabelLists. I published the source code at: https://github.com/lvcabral/SGDatePicker – Marcelo Lv Cabral Jul 28 '17 at 03:26

2 Answers2

1

What you can do depends if you are writing the app SDK1 (the older but simple components that are being deprecated now) or RSG (Roku Scene Graph - the newer, way more complex way of implementing) style.

If using RSG, i would think LabelList is a good start to implement something akin to iOS's UIDatePicker. E.g. with remote Up-Down user selects month, then press Right to move to the day column, then Right onto the year list.

Nas Banov
  • 28,347
  • 6
  • 48
  • 67
1

The solution I ended up using was to use a regular text keyboard, and validate the input with regex:

getText: function(ageValidate as Boolean, defaultText as String, displayText as String) as String
        screen = CreateObject("roKeyboardScreen")
        port = CreateObject("roMessagePort")

        screen.SetMessagePort(port)
        screen.SetDisplayText(displayText)
        screen.SetText(defaultText)
        screen.SetMaxLength(100)
        screen.AddButton(1, "done")
        screen.AddButton(2, "back")
        screen.Show()

        while true
            msg = wait(0, screen.GetMessagePort())
            if type(msg) = "roKeyboardScreenEvent"
                if msg.isScreenClosed()
                    return ""
                else if msg.isButtonPressed() then
                    if ageValidate = true AND m.isValidDate(text) = false then
                            "Invalid Input", "Input your birthdate in the format MMDDYYYY", "okay")
                        else if text = invalid OR text = ""
                            showUserDialog("Error"), "no input", "okay")
                        else
                            screen.Close()
                            return text
                        end if
                    else if msg.GetIndex() = 2
                        screen.Close()
                        return ""
                    end if
                end if
            end if
        end while
end function

isValidDate: function(date as String) as Boolean
    return CreateObject("roRegex", "(0[1-9]|1[012])[-.]?(0[1-9]|[12][0-9]|3[01])[-.]?(19|20)[0-9]{2}", "i").IsMatch(date)
end function
Cassidy
  • 3,328
  • 5
  • 39
  • 76