This is an automated email from the ASF dual-hosted git repository.
bbovenzi pushed a commit to branch v2-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v2-10-test by this push:
new 74d31ba0b4 Support multiline input for Params of type string in
trigger UI form (#40414) (#42139)
74d31ba0b4 is described below
commit 74d31ba0b4a93881fecd5a10463862f53f2c83ff
Author: Jens Scheffler <[email protected]>
AuthorDate: Tue Sep 10 21:10:52 2024 +0200
Support multiline input for Params of type string in trigger UI form
(#40414) (#42139)
* 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
Co-authored-by: sc-anssi <[email protected]>
---
airflow/example_dags/example_params_ui_tutorial.py | 6 ++++++
airflow/www/templates/airflow/trigger.html | 6 ++++++
docs/apache-airflow/core-concepts/params.rst | 3 ++-
3 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/airflow/example_dags/example_params_ui_tutorial.py
b/airflow/example_dags/example_params_ui_tutorial.py
index f7fd7e0844..133df85d07 100644
--- a/airflow/example_dags/example_params_ui_tutorial.py
+++ b/airflow/example_dags/example_params_ui_tutorial.py
@@ -165,6 +165,12 @@ with DAG(
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.
diff --git a/airflow/www/templates/airflow/trigger.html
b/airflow/www/templates/airflow/trigger.html
index eb098dd21d..158b54caba 100644
--- a/airflow/www/templates/airflow/trigger.html
+++ b/airflow/www/templates/airflow/trigger.html
@@ -129,6 +129,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 %}"
diff --git a/docs/apache-airflow/core-concepts/params.rst
b/docs/apache-airflow/core-concepts/params.rst
index a4efceb366..e93161a7b2 100644
--- a/docs/apache-airflow/core-concepts/params.rst
+++ b/docs/apache-airflow/core-concepts/params.rst
@@ -232,7 +232,7 @@ 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
@@ -240,6 +240,7 @@ The following features are supported in the Trigger UI Form:
* | ``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