From 460240f331919510e18aaff5da8a016e6c336d13 Mon Sep 17 00:00:00 2001 From: avdata99 Date: Thu, 27 Jun 2024 15:07:01 -0300 Subject: [PATCH 1/2] False is also a value --- ckanext/scheming/templates/scheming/form_snippets/select.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/scheming/templates/scheming/form_snippets/select.html b/ckanext/scheming/templates/scheming/form_snippets/select.html index de889c24..1adb7cec 100644 --- a/ckanext/scheming/templates/scheming/form_snippets/select.html +++ b/ckanext/scheming/templates/scheming/form_snippets/select.html @@ -16,7 +16,7 @@ {%- if field.get('sorted_choices') -%} {%- set options = options|sort(case_sensitive=false, attribute='text') -%} {%- endif -%} -{%- if data[field.field_name] -%} +{%- if data[field.field_name] or data[field.field_name] is false -%} {%- set option_selected = data[field.field_name]|string -%} {%- else -%} {%- set option_selected = None -%} From 1341c40fc5ec69f49de6a26b289fd90ee13c3c68 Mon Sep 17 00:00:00 2001 From: avdata99 Date: Thu, 27 Jun 2024 15:38:55 -0300 Subject: [PATCH 2/2] Improve false detection --- ckanext/scheming/templates/scheming/form_snippets/radio.html | 2 +- ckanext/scheming/templates/scheming/form_snippets/select.html | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ckanext/scheming/templates/scheming/form_snippets/radio.html b/ckanext/scheming/templates/scheming/form_snippets/radio.html index f4bf686d..ff363148 100644 --- a/ckanext/scheming/templates/scheming/form_snippets/radio.html +++ b/ckanext/scheming/templates/scheming/form_snippets/radio.html @@ -16,7 +16,7 @@ {%- if field.get('sorted_choices') -%} {%- set options = options|sort(case_sensitive=false, attribute='text') -%} {%- endif -%} -{%- if data[field.field_name] -%} +{%- if data[field.field_name] is defined -%} {%- set option_selected = data[field.field_name]|string -%} {%- else -%} {%- set option_selected = None -%} diff --git a/ckanext/scheming/templates/scheming/form_snippets/select.html b/ckanext/scheming/templates/scheming/form_snippets/select.html index 1adb7cec..619e8fec 100644 --- a/ckanext/scheming/templates/scheming/form_snippets/select.html +++ b/ckanext/scheming/templates/scheming/form_snippets/select.html @@ -16,8 +16,10 @@ {%- if field.get('sorted_choices') -%} {%- set options = options|sort(case_sensitive=false, attribute='text') -%} {%- endif -%} -{%- if data[field.field_name] or data[field.field_name] is false -%} +{%- if data[field.field_name] is defined -%} {%- set option_selected = data[field.field_name]|string -%} +{%- elif field.default is defined -%} + {%- set option_selected = field.default|string -%} {%- else -%} {%- set option_selected = None -%} {%- endif -%}