Removing default text when participant enters text

PennController for IBEX Forums Support Removing default text when participant enters text

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #9609
    mawilson
    Participant

    I want to record some information from participants using a TextInput element. However, when I click on the text area and begin typing, the default text remains in the text area. Is there a way to clear this text when the participant has entered their own text?

    The demo link is here: https://farm.pcibex.net/r/JJwfIj/.
    Here’s what the relevant code snippet is:

    
    newTextInput('text', 'This is the default text.')
        .print()
    

    This produces a text input area with the default text “This is the default text.” Clicking on the area and entering text appends the entered text to the end of the default text unless you manually clear it.

    • This topic was modified 1 year, 6 months ago by mawilson. Reason: code tags
    • This topic was modified 1 year, 6 months ago by mawilson. Reason: code tags
    #9617
    Jeremy
    Keymaster

    Hi,

    What you describe is the placeholder attribute of the HTML textarea element, and PennController does not provide a direct command to set it, but it actually isn’t that hard to implement:

    newTextInput('text').print()
    ,
    // The bit after the dash ('text') needs to match the name of the TextInput element
    newFunction( ()=>document.querySelector("textarea.PennController-text").placeholder = 'This is the default text.' ).call()
    ,

    Jeremy

    #9631
    mawilson
    Participant

    Thank you!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.