Filled TextInput

PennController for IBEX Forums Support Filled TextInput

This topic contains 5 replies, has 3 voices, and was last updated by Avatar daniela 2 months, 1 week ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5189
    Avatar
    Lynn
    Participant

    Hello Jeremy,

    I have been trying to find some settings for the TextInput Elements in my code below :
    1) How can I make sure that the “Continue” button doesn’t take effect if some of the TextInput Elements are not filled ?
    2) Is there some way to adjust the TextInput answers to be strictly between 2 certain numbers ? i.e. : in the “age” TextInput below, if the number written is less than 18, it’s not validated.

        newText("age", "<p></p>Age (years):")
            .print()
        ,
        newTextInput("age")
            .settings.length(2)
            .print()
            .log()
        ,
        newText("height", "<p></p>Height (cm):")
            .print()
        ,
        newTextInput("height")
            .settings.length(3)
            .print()
            .log()
        ,
        newText("weight", "<p></p>Weight (kg):")
            .print()
        ,
        newTextInput("weight")
            .settings.length(3)
            .print()
            .log()
        ,
        newText("<p></p>")
            .print()
        ,
        newButton("Continue")
            .color("green")
            .print()
            .wait()

    Thank you so much in advance for your help.
    Sincerely,

    #5194
    Jeremy
    Jeremy
    Keymaster

    Hello,

    Yes, you can use .test.text to check the content of a TextInput element, and doing so in the wait command will only validate the click if the test is successful. In your case, you can use regular expressions to check for appropriate numbers, just replace your very last .wait() line with this:

    .wait(
        getTextInput("age").test.text( /^(\d|1[0-8])$/ )
            .failure( newText("Age should be a number between 0 and 18").print() )
        .and( getTextInput("weight").test.text( /^\d+$/ )
            .failure( newText("Weight should be a numeric value").print() )
        ).and( getTextInput("height").test.text( /^\d+$/ )
            .failure( newText("Height should be a numeric value").print() )
        )
    )

    Jeremy

    #5196
    Avatar
    Lynn
    Participant

    Thank you so much for your fast reply !

    #6079
    Avatar
    daniela
    Participant

    Hi Jeremy,

    is there a way to adapt test.text() to test whether or not the textInput element isn’t empty? It seems like the most standard test for a textInput element, but I can’t seem to find the solution anywhere!

    Best,
    Daniela

    #6080
    Jeremy
    Jeremy
    Keymaster

    Hi Daniela,

    You can take two approaches: either use a negative test testNot.text("") or a positive test using a regex test.text(/[^\s]+/). The latter is more powerful, as it will only validate non-empty text, whereas the former would succeed even if the text only consists of spaces, for example

    Jeremy

    #6126
    Avatar
    daniela
    Participant

    Hi Jeremy,

    that’s great, thank you again!

    – Daniela

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.