]> saetta.ns0.it Git - zakform/cgi/commitdiff
Added functions FormElement::*_attr.
authorAndrea Zagli <azagli@libero.it>
Sun, 29 Nov 2020 12:05:57 +0000 (13:05 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 29 Nov 2020 12:05:57 +0000 (13:05 +0100)
src/formelement.c
src/formelement.h

index 647a942ff01638fb168f230a297b57a4cae8338b..32a16b5314e22c1b7e65fe7ed30db2819be715ec 100644 (file)
@@ -233,7 +233,7 @@ gchar
 
                        if (!zak_form_element_get_editable (ZAK_FORM_ELEMENT (element)))
                                {
-                                       g_hash_table_insert (priv->ht_attrs, (gpointer)"readonly", (gpointer)"readonly");
+                                       zak_form_cgi_form_element_set_attr (element, "readonly", "readonly");
                                }
 
                        g_string_append (str, ZAK_FORM_CGI_FORM_ELEMENT_GET_CLASS (element)->render (element));
@@ -305,6 +305,45 @@ gchar
        return ret;
 }
 
+gchar
+*zak_form_cgi_form_element_get_attr (ZakFormCgiFormElement *element, const gchar *attr)
+{
+       ZakFormCgiFormElementPrivate *priv;
+
+       priv = ZAK_FORM_CGI_FORM_ELEMENT_GET_PRIVATE (element);
+
+       if (priv->ht_attrs == NULL)
+               {
+                       return NULL;
+               }
+       else
+               {
+                       return g_hash_table_lookup (priv->ht_attrs, attr);
+               }
+}
+
+void
+zak_form_cgi_form_element_set_attr (ZakFormCgiFormElement *element, const gchar *attr, const gchar *value)
+{
+       ZakFormCgiFormElementPrivate *priv;
+
+       priv = ZAK_FORM_CGI_FORM_ELEMENT_GET_PRIVATE (element);
+
+       if (priv->ht_attrs == NULL)
+               {
+                       priv->ht_attrs = g_hash_table_new (g_str_hash, g_str_equal);
+               }
+
+       if (value == NULL)
+               {
+                       g_hash_table_remove (priv->ht_attrs, attr);
+               }
+       else
+               {
+                       g_hash_table_insert (priv->ht_attrs, g_strdup (attr), g_strdup (value));
+               }
+}
+
 gboolean
 zak_form_cgi_form_element_has_class (ZakFormCgiFormElement *element, const gchar *class)
 {
@@ -440,7 +479,7 @@ zak_form_cgi_form_element_construct (ZakFormCgiFormElement *element,
 
        if (g_hash_table_lookup (priv->ht_attrs, "name") == NULL)
                {
-                       g_hash_table_insert (priv->ht_attrs, "name", g_strdup (id));
+                       zak_form_cgi_form_element_set_attr (element, "name", id);
                }
        zak_form_element_set_name (ZAK_FORM_ELEMENT (element), g_hash_table_lookup (priv->ht_attrs, "name"));
 
index 918011444762486a45c39b1217e497fe7ab938f2..03815b9ab463b6dd85d8bae4cb6c368977fde372 100644 (file)
@@ -55,6 +55,9 @@ void zak_form_cgi_form_element_bind (ZakFormCgiFormElement *element, GValue *val
 gchar *zak_form_cgi_form_element_render (ZakFormCgiFormElement *element);
 gchar *zak_form_cgi_form_element_render_label (ZakFormCgiFormElement *element);
 
+gchar *zak_form_cgi_form_element_get_attr (ZakFormCgiFormElement *element, const gchar *attr);
+void zak_form_cgi_form_element_set_attr (ZakFormCgiFormElement *element, const gchar *attr, const gchar *value);
+
 gboolean zak_form_cgi_form_element_has_class (ZakFormCgiFormElement *element, const gchar *class);
 void zak_form_cgi_form_element_add_class (ZakFormCgiFormElement *element, const gchar *class);
 void zak_form_cgi_form_element_remove_class (ZakFormCgiFormElement *element, const gchar *class);