{% if schema['units'] is string or schema['units'] | length == 1 %} {% set unit = schema["units"] if schema["units"] is string else schema["units"][0] %} {% else %}
{% if id_prefix + '_units' in form_data %} {% set selected_unit = form_data[id_prefix + '_units'] %} {% elif data is not none %} {% set selected_unit = (data | to_datatype).units %} {% else %} {% set selected_unit = schema['units'][0] %} {% endif %}
{% endif %}