Changed content special attribute in zak-cgi-content for tags.
#include "commons.h"
#include "formelement.h"
+#include "tag.h"
enum
{
gchar *validation_regex;
GHashTable *ht_attrs;
GValue *value;
+ GHashTable *ht_label_attrs;
};
G_DEFINE_TYPE (ZakCgiFormElement, zak_cgi_form_element, G_TYPE_OBJECT)
priv->validation_regex = NULL;
priv->ht_attrs = NULL;
priv->value = NULL;
+ priv->ht_label_attrs = NULL;
}
gchar
return priv->value;
}
+/**
+ * zak_cgi_form_element_set_label:
+ * @element:
+ * @label:
+ * @...:
+ *
+ */
+void
+zak_cgi_form_element_set_label (ZakCgiFormElement *element, const gchar *label, ...)
+{
+ va_list ap;
+
+ ZakCgiFormElementPrivate *priv;
+
+ priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element);
+
+ if (priv->ht_label_attrs != NULL)
+ {
+ g_hash_table_destroy (priv->ht_label_attrs);
+ }
+
+ va_start (ap, label);
+ priv->ht_label_attrs = zak_cgi_commons_valist_to_ghashtable (ap);
+
+ 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"));
+}
+
/**
* zak_cgi_form_element_render:
* @element:
gchar
*zak_cgi_form_element_render (ZakCgiFormElement *element)
{
+ GString *str;
gchar *ret;
- ret = g_strdup ("");
+ ZakCgiFormElementPrivate *priv;
+
+ priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element);
+
+ str = g_string_new ("");
+
+ if (priv->ht_label_attrs != NULL)
+ {
+ gchar *lbl_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 (ZAK_CGI_IS_FORM_ELEMENT (element) && ZAK_CGI_FORM_ELEMENT_GET_CLASS (element)->render != NULL)
{
- ret = ZAK_CGI_FORM_ELEMENT_GET_CLASS (element)->render (element);
+ g_string_append (str, ZAK_CGI_FORM_ELEMENT_GET_CLASS (element)->render (element));
}
+ ret = g_strdup (str->str);
+ g_string_free (str, TRUE);
+
return ret;
}
void zak_cgi_form_element_set_value (ZakCgiFormElement *element, GValue *value);
GValue *zak_cgi_form_element_get_value (ZakCgiFormElement *element);
+void zak_cgi_form_element_set_label (ZakCgiFormElement *element, const gchar *label, ...);
+
gchar *zak_cgi_form_element_render (ZakCgiFormElement *element);
gboolean zak_cgi_form_element_is_valid (ZakCgiFormElement *element);
g_hash_table_iter_init (&iter, ht_attrs);
while (g_hash_table_iter_next (&iter, &key, &val))
{
- if (g_strcmp0 ((gchar *)key, "content") == 0)
+ if (g_strcmp0 ((gchar *)key, "zak-cgi-content") == 0)
{
with_content = TRUE;
if (content != NULL)
NULL);
element = zak_cgi_form_element_text_new ("first", "aaa", NULL);
+ zak_cgi_form_element_set_label (element, "The Label for first", NULL);
zak_cgi_form_add_element (form, element);
zak_cgi_form_add_str (form, "<h1>big big big</h1>");
NULL));
g_string_append_printf (str, "%s<br/>\n", zak_cgi_tag_tag ("textarea", "textarea",
- "content", "the content of the text area",
+ "zak-cgi-content", "the content of the text area",
NULL));
g_string_append_printf (str, "%s<br/>\n", zak_cgi_tag_img ("theimage", "src", "pippo.png", NULL));
g_string_append_printf (select_content,
zak_cgi_tag_tag ("option", NULL,
"value", "1",
- "content", "One",
+ "zak-cgi-content", "One",
NULL));
g_string_append_printf (select_content,
zak_cgi_tag_tag ("option", NULL,
"value", "2",
- "content", "Two",
+ "zak-cgi-content", "Two",
NULL));
g_string_append_printf (select_content,
zak_cgi_tag_tag ("option", NULL,
"value", "3",
- "content", "Three",
+ "zak-cgi-content", "Three",
NULL));
- g_string_append_printf (str, "%s<br/>\n", zak_cgi_tag_tag ("select", "idselect", "content", select_content->str, NULL));
+ g_string_append_printf (str, "%s<br/>\n", zak_cgi_tag_tag ("select", "idselect", "zak-cgi-content", select_content->str, NULL));
zak_cgi_main_out (NULL, str->str);