From d2a1db17b494e527a96f24b71a889f27650b438c Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 16 Aug 2020 17:56:12 +0200 Subject: [PATCH] Implemented ::load. --- src/form.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/src/form.c b/src/form.c index 278611c..ddd5b48 100644 --- a/src/form.c +++ b/src/form.c @@ -441,7 +441,45 @@ zak_form_json_provider_load (ZakFormIProvider *provider, GPtrArray *elements) ZakFormElement *element = (ZakFormElement *)g_ptr_array_index (elements, i); if (zak_form_element_get_to_load (element)) { - zak_form_element_set_value (element, json_object_get_string_member (obj, zak_form_element_get_name (element))); + JsonNode *jnode; + + jnode = json_object_get_member (obj, zak_form_element_get_name (element)); + if (ZAK_FORM_IS_ELEMENT_ARRAY (element) + && json_node_get_node_type (jnode) == JSON_NODE_ARRAY) + { + guint l; + guint j; + JsonArray *ar; + + GString *str; + + str = g_string_new (""); + + ar = json_node_get_array (jnode); + l = json_array_get_length (ar); + for (j = 0; j < l; j++) + { + JsonObject *ar_obj; + GList *lst_membs; + + ar_obj = json_array_get_object_element (ar, j); + lst_membs = json_object_get_members (ar_obj); + + g_string_append_printf (str, + "%s{\"%s\",\"%s\"}", + str->len > 1 ? "," : "", + (gchar *)lst_membs->data, + json_object_get_string_member (ar_obj, (const gchar *)lst_membs->data)); + } + + zak_form_element_set_value (element, str->str); + + g_string_free (str, TRUE); + } + else + { + zak_form_element_set_value (element, json_object_get_string_member (obj, zak_form_element_get_name (element))); + } zak_form_element_set_as_original_value (element); } } -- 2.49.0