Skip to content

Commit

Permalink
Support multiline input for Params of type string in trigger UI form (#…
Browse files Browse the repository at this point in the history
…40414)

* Add multiline input (textarea) support for Params of type string in trigger UI form

* Use the 'format' attribute in the Param for rendering a multiline text area in the trigger UI form

* Update example DAG and documentation to illustrate the use of a multiline text Param
  • Loading branch information
sc-anssi authored Sep 10, 2024
1 parent ccc897a commit 46306f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions airflow/example_dags/example_params_ui_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@
title="Time Picker",
description="Please select a time, use the button on the left for a pop-up tool.",
),
"multiline_text": Param(
"A multiline text Param\nthat will keep the newline\ncharacters in its value.",
description="This field allows for multiline text input. The returned value will be a single with newline (\\n) characters kept intact.",
type=["string", "null"],
format="multiline",
),
# Fields can be required or not. If the defined fields are typed they are getting required by default
# (else they would not pass JSON schema validation) - to make typed fields optional you must
# permit the optional "null" type.
Expand Down
6 changes: 6 additions & 0 deletions airflow/www/templates/airflow/trigger.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@
{%- if form_details.schema.minimum %} min="{{ form_details.schema.minimum }}"{% endif %}
{%- if form_details.schema.maximum %} max="{{ form_details.schema.maximum }}"{% endif %}
{%- if form_details.schema.type and not "null" in form_details.schema.type %} required=""{% endif %} />
{% elif form_details.schema and "string" in form_details.schema.type and "format" in form_details.schema and form_details.schema.format == "multiline" %}
<textarea class="form-control" name="element_{{ form_key }}" id="element_{{ form_key }}" rows="6"
{%- if not "null" in form_details.schema.type %} required=""{% endif -%}
{%- if form_details.schema and form_details.schema.minLength %} minlength="{{ form_details.schema.minLength }}"{% endif %}
{%- if form_details.schema and form_details.schema.maxLength %} maxlength="{{ form_details.schema.maxLength }}"{% endif %}
>{% if form_details.value %}{{- form_details.value -}}{% endif %}</textarea>
{% else %}
<input class="form-control" name="element_{{ form_key }}" id="element_{{ form_key }}"
type="{% if "examples" in form_details.schema and form_details.schema.examples %}search{% else %}text{% endif %}"
Expand Down
3 changes: 2 additions & 1 deletion docs/apache-airflow/core-concepts/params.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,15 @@ The following features are supported in the Trigger UI Form:
- Example

* - ``string``
- Generates a single-line text box to edit text.
- Generates a single-line text box or a text area to edit text.
- * ``minLength``: Minimum text length
* ``maxLength``: Maximum text length
* | ``format="date"``: Generate a date-picker
| with calendar pop-up
* | ``format="date-time"``: Generate a date and
| time-picker with calendar pop-up
* ``format="time"``: Generate a time-picker
* ``format="multiline"``: Generate a multi-line textarea
* | ``enum=["a", "b", "c"]``: Generates a
| drop-down select list for scalar values.
| As of JSON validation, a value must be
Expand Down

0 comments on commit 46306f5

Please sign in to comment.