From 23239fae294f17b9b825000f41fdf2dec3c6422d Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 1 Nov 2015 17:12:05 +0100 Subject: [PATCH] Use of messages from ZakFormElementValidator. --- src/formelement.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/formelement.c b/src/formelement.c index 77abc0e..5e8d1fd 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -125,6 +125,7 @@ zak_cgi_form_element_set_label (ZakCgiFormElement *element, const gchar *label, g_hash_table_replace (priv->ht_label_attrs, "zak-cgi-content", g_strdup (label)); g_hash_table_replace (priv->ht_label_attrs, "for", g_hash_table_lookup (priv->ht_attrs, "name")); + g_hash_table_replace (priv->ht_label_attrs, "class", "control-label"); } /** @@ -137,12 +138,21 @@ gchar { GString *str; gchar *ret; + GPtrArray *messages; ZakCgiFormElementPrivate *priv; priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); - str = g_string_new ("
\n"); + str = g_string_new ("
get_messages (ZAK_FORM_ELEMENT (element)); + if (messages != NULL) + { + g_string_append (str, " has-error"); + } + + g_string_append (str, "\">\n"); if (priv->ht_label_attrs != NULL) { @@ -174,6 +184,20 @@ gchar g_string_append (str, ZAK_CGI_FORM_ELEMENT_GET_CLASS (element)->render (element)); } + if (messages != NULL) + { + guint i; + + for (i = 0; i < messages->len; i++) + { + g_string_append_printf (str, + "\n%s", + priv->id, + i + 1, + (gchar *)g_ptr_array_index (messages, i)); + } + } + g_string_append (str, "\n
\n"); ret = g_strdup (str->str); -- 2.49.0