diff --git a/taipy/gui/_renderers/builder.py b/taipy/gui/_renderers/builder.py index 8c86c4a7e3..b877ef5d03 100644 --- a/taipy/gui/_renderers/builder.py +++ b/taipy/gui/_renderers/builder.py @@ -377,11 +377,13 @@ def __set_string_or_number_attribute(self, name: str, default_value: t.Optional[ def __set_react_attribute(self, name: str, value: t.Any): return self.set_attribute(name, "{!" + (str(value).lower() if isinstance(value, bool) else str(value)) + "!}") - def _get_lov_adapter(self, var_name: str, property_name: t.Optional[str] = None, multi_selection=True): # noqa: C901 + def _get_lov_adapter( # noqa: C901 + self, var_name: str, property_name: t.Optional[str] = None, multi_selection=True, with_default=True + ): property_name = var_name if property_name is None else property_name lov_name = self.__hashes.get(var_name) lov = self.__get_list_of_(var_name) - default_lov = [] + default_lov: t.Optional[t.List[t.Any]] = [] if with_default or not lov_name else None adapter = self.__attributes.get("adapter") if adapter and isinstance(adapter, str): @@ -396,15 +398,15 @@ def _get_lov_adapter(self, var_name: str, property_name: t.Optional[str] = None, if isinstance(lov, list): if not isinstance(var_type, str): elt = None - if len(lov) == 0: + if lov: + elt = lov[0] + else: value = self.__attributes.get("value") if isinstance(value, list): if len(value) > 0: elt = value[0] else: elt = value - else: - elt = lov[0] var_type = self.__gui._get_unique_type_adapter(type(elt).__name__) if adapter is None: adapter = self.__gui._get_adapter_for_type(var_type) @@ -427,7 +429,7 @@ def _get_lov_adapter(self, var_name: str, property_name: t.Optional[str] = None, if adapter is not None: self.__gui._add_adapter_for_type(var_type, adapter) # type: ignore - if len(lov) > 0: + if default_lov is not None and lov: for elt in lov: ret = self.__gui._run_adapter( t.cast(t.Callable, adapter), elt, adapter.__name__ if callable(adapter) else "adapter" @@ -453,7 +455,8 @@ def _get_lov_adapter(self, var_name: str, property_name: t.Optional[str] = None, self.__set_default_value("value", ret_val) # LoV default value - self.__set_json_attribute(_to_camel_case(f"default_{property_name}"), default_lov) + if default_lov is not None: + self.__set_json_attribute(_to_camel_case(f"default_{property_name}"), default_lov) # LoV expression binding if lov_name: @@ -1031,8 +1034,16 @@ def set_attributes(self, attributes: t.List[tuple]): # noqa: C901 self.__set_dynamic_date_attribute(attr[0], _get_tuple_val(attr, 2, None)) elif var_type == PropertyType.data: self.__set_dynamic_property_without_default(attr[0], var_type) - elif var_type == PropertyType.lov or var_type == PropertyType.single_lov: - self._get_lov_adapter(attr[0], multi_selection=var_type != PropertyType.single_lov) + elif ( + var_type == PropertyType.lov + or var_type == PropertyType.single_lov + or var_type == PropertyType.lov_no_default + ): + self._get_lov_adapter( + attr[0], + multi_selection=var_type != PropertyType.single_lov, + with_default=var_type != PropertyType.lov_no_default, + ) elif var_type == PropertyType.lov_value: self.__set_dynamic_property_without_default( attr[0], var_type, _get_tuple_val(attr, 2, None) == "optional" diff --git a/taipy/gui/types.py b/taipy/gui/types.py index b9e4f3ec02..6a3a085094 100644 --- a/taipy/gui/types.py +++ b/taipy/gui/types.py @@ -118,6 +118,7 @@ class PropertyType(Enum): json = "json" single_lov = "singlelov" lov = _TaipyLov + lov_no_default = "lovnodefault" """ The property holds a LoV (list of values). """ diff --git a/taipy/gui_core/_GuiCoreLib.py b/taipy/gui_core/_GuiCoreLib.py index 82bf0aa406..501cbbdcc9 100644 --- a/taipy/gui_core/_GuiCoreLib.py +++ b/taipy/gui_core/_GuiCoreLib.py @@ -87,7 +87,7 @@ class _GuiCore(ElementLibrary): }, inner_properties={ "inner_scenarios": ElementProperty( - PropertyType.lov, + PropertyType.lov_no_default, f"{{{__CTX_VAR_NAME}.get_scenarios(, " + f"{__SCENARIO_SELECTOR_FILTER_VAR}, " + f"{__SCENARIO_SELECTOR_SORT_VAR})}}", @@ -182,7 +182,7 @@ class _GuiCore(ElementLibrary): }, inner_properties={ "inner_datanodes": ElementProperty( - PropertyType.lov, + PropertyType.lov_no_default, f"{{{__CTX_VAR_NAME}.get_datanodes_tree(, " + f", " + f"{__DATANODE_SELECTOR_FILTER_VAR}, "