]> saetta.ns0.it Git - zakform/cgi/commitdiff
Added function ZakFormCgiFormElement::render_label.
authorAndrea Zagli <azagli@libero.it>
Sat, 6 May 2017 07:39:02 +0000 (09:39 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 6 May 2017 07:39:02 +0000 (09:39 +0200)
src/formelement.c
src/formelement.h

index f8a3cd6cf69c4eed4a4068b2245ef6ca0d675131..ff070021922812a25ff17f49ff049df64ab5086e 100644 (file)
@@ -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 ("<div class=\"form-group");
+
+                       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);
+               }
+
+       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,
index ab8406f7398f06654cd17eceea84e606c877eb73..a8da1df06644fbb8f53550418293df306e87a10f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2015-2016 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2017 Andrea Zagli <azagli@libero.it>
  *
  * 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