posit-dev / py-shiny

Shiny for Python
https://shiny.posit.co/py/
MIT License
1.31k stars 79 forks source link

Add option to send text input only after pressing return key #495

Open vnijs opened 1 year ago

vnijs commented 1 year ago

Ask: Please consider adding an option to input_text_input and input_text_area_input to only send new input information after the user presses the return key. Below links to the bindings I have used with R-shiny.

Why: My apps ask users to input filters, arguments, and commands. This will throw errors if the user input is not complete. Adding an input_action_button works only for the first text entry. Once the action button has been pushed, any changes to the user text input are immediately sent for processing.

I have tested the js scripts linked below with the input_text_area function below and it works. All that should be needed is to (1) source the js and (2) append "returnTextArea" to the classes list.

Thank you for your consideration.

https://github.com/radiant-rstats/radiant.data/blob/master/inst/app/www/js/returnTextAreaBinding.js

https://github.com/radiant-rstats/radiant.data/blob/master/inst/app/www/js/returnTextInputBinding.js

def input_return_text_area(
    id,
    label,
    value="",
    rows=1,
    placeholder="",
    resize="vertical",
    autocomplete=False,
    spellcheck=False,
):
    classes = ["form-control", "returnTextArea"]
    area = tags.textarea(
        value,
        id=id,
        class_=" ".join(classes),
        style=css(width="100%", height=None, resize=resize),
        placeholder=placeholder,
        rows=rows,
        cols=None,
        autocomplete=autocomplete,
        spellcheck=spellcheck,
    )

    def shiny_input_label(id, label=None):
        cls = "control-label" + ("" if label else " shiny-label-null")
        return tags.label(label, class_=cls, id=id + "-label", for_=id)

    return div(
        shiny_input_label(id, label),
        area,
        None,
        class_="form-group shiny-input-container",
        style=css(width="100%"),
    )
wch commented 1 year ago

This is the same as #449. I agree that this would be very useful.