From 24d381d477572b01612f4c64d604a67a661f12fa Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 6 May 2017 09:39:02 +0200 Subject: [PATCH] Added function ZakFormCgiFormElement::render_label. --- src/formelement.c | 60 +++++++++++++++++++++++++++++++++++++---------- src/formelement.h | 3 ++- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/formelement.c b/src/formelement.c index f8a3cd6..ff07002 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -187,19 +187,7 @@ gchar g_string_append (str, "\">\n"); - if (priv->ht_label_attrs != NULL) - { - gchar *lbl_id; - - if (g_strcmp0 (g_hash_table_lookup (priv->ht_label_attrs, "for"), "") == 0) - { - g_hash_table_replace (priv->ht_label_attrs, "for", g_strdup (priv->id)); - } - - lbl_id = g_strdup_printf ("lbl_%s", priv->id); - g_string_append (str, zak_cgi_tag_tag_ht ("label", lbl_id, priv->ht_label_attrs)); - g_free (lbl_id); - } + zak_form_cgi_form_element_render_label (element); if (ZAK_FORM_CGI_IS_FORM_ELEMENT (element) && ZAK_FORM_CGI_FORM_ELEMENT_GET_CLASS (element)->render != NULL) { @@ -247,6 +235,52 @@ gchar return ret; } +/** + * zak_form_cgi_form_element_render_label: + * @element: + * + */ +gchar +*zak_form_cgi_form_element_render_label (ZakFormCgiFormElement *element) +{ + GString *str; + gchar *ret; + gchar *lbl_id; + + ZakFormCgiFormElementPrivate *priv; + + priv = ZAK_FORM_CGI_FORM_ELEMENT_GET_PRIVATE (element); + + str = NULL; + + if (priv->ht_label_attrs != NULL) + { + + str = g_string_new ("
ht_label_attrs, "for"), "") == 0) + { + g_hash_table_replace (priv->ht_label_attrs, "for", g_strdup (priv->id)); + } + + lbl_id = g_strdup_printf ("lbl_%s", priv->id); + g_string_append (str, zak_cgi_tag_tag_ht ("label", lbl_id, priv->ht_label_attrs)); + g_free (lbl_id); + } + + if (str != NULL) + { + ret = g_strdup (str->str); + g_string_free (str, TRUE); + } + else + { + ret = g_strdup (""); + } + + return ret; +} + /* PRIVATE */ static void zak_form_cgi_form_element_construct (ZakFormCgiFormElement *element, diff --git a/src/formelement.h b/src/formelement.h index ab8406f..a8da1df 100644 --- a/src/formelement.h +++ b/src/formelement.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2016 Andrea Zagli + * Copyright (C) 2015-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -51,6 +51,7 @@ void zak_form_cgi_form_element_set_label (ZakFormCgiFormElement *element, const void zak_form_cgi_form_element_bind (ZakFormCgiFormElement *element, const gchar *value); gchar *zak_form_cgi_form_element_render (ZakFormCgiFormElement *element); +gchar *zak_form_cgi_form_element_render_label (ZakFormCgiFormElement *element); G_END_DECLS -- 2.49.0