Added element for error message to FormValidatorCompareNumber.
authorAndrea Zagli <azagli@libero.it>
Wed, 6 Jan 2021 09:30:15 +0000 (10:30 +0100)
committerAndrea Zagli <azagli@libero.it>
Wed, 6 Jan 2021 09:30:15 +0000 (10:30 +0100)
src/formvalidatorcomparedate.c
src/formvalidatorcomparenumber.c
src/formvalidatorcomparenumber.h

index 83a1965cc652be26eaebf7ba1505d7ebe56fdfb7..977fd624f586e1e3ed6e308170f0ceb945520957 100644 (file)
@@ -144,6 +144,10 @@ zak_form_validator_compare_date_xml_parsing (ZakFormValidator *validator, xmlNod
        g_free (prop);
        g_free (prop2);
 
+       prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"element_message");
+       zak_form_validator_compare_date_set_element_message ((ZakFormValidatorCompareDate *)validator, (ZakFormForm *)form, prop);
+       g_free (prop);
+
        return TRUE;
 }
 
@@ -455,6 +459,12 @@ zak_form_validator_compare_date_validate (ZakFormValidator *validator)
                                                               zak_form_get_compare_type_stringify (priv->type),
                                                               zak_form_element_get_long_name (priv->v2));
                                        zak_form_validator_set_message (validator, msg);
+
+                                       if (priv->message != NULL)
+                                               {
+                                                       zak_form_element_add_message (priv->message, msg);
+                                               }
+
                                        g_free (msg);
                                }
 
index f5d37dbc66cddcb7b9cfd64e6801828d7c1055e3..007a8af8bd83d0a48eed796234cc92a5ca16d818 100644 (file)
@@ -62,6 +62,8 @@ struct _ZakFormValidatorCompareNumberPrivate
 
                ZakFormElement *v1;
                ZakFormElement *v2;
+
+               ZakFormElement *message;
        };
 
 G_DEFINE_TYPE_WITH_PRIVATE (ZakFormValidatorCompareNumber, zak_form_validator_compare_number, ZAK_FORM_TYPE_VALIDATOR)
@@ -89,6 +91,7 @@ zak_form_validator_compare_number_init (ZakFormValidatorCompareNumber *validator
 
        priv->v1 = NULL;
        priv->v2 = NULL;
+       priv->message = NULL;
 }
 
 /**
@@ -132,6 +135,10 @@ zak_form_validator_compare_number_xml_parsing (ZakFormValidator *validator, xmlN
        zak_form_validator_compare_number_set_element2 ((ZakFormValidatorCompareNumber *)validator, (ZakFormForm *)form, prop);
        g_free (prop);
 
+       prop = (gchar *)xmlGetProp (xnode, (const xmlChar *)"element_message");
+       zak_form_validator_compare_number_set_element_message ((ZakFormValidatorCompareNumber *)validator, (ZakFormForm *)form, prop);
+       g_free (prop);
+
        return TRUE;
 }
 
@@ -244,6 +251,46 @@ const gchar
                }
 }
 
+/**
+ * zak_form_validator_compare_number_set_element_message:
+ * @validator:
+ * @element:
+ *
+ * Sets the validator element for error message.
+ */
+void
+zak_form_validator_compare_number_set_element_message (ZakFormValidatorCompareNumber *validator, ZakFormForm *form, const gchar *element)
+{
+       ZakFormValidatorCompareNumberPrivate *priv = zak_form_validator_compare_number_get_instance_private (validator);
+
+       priv->message = zak_form_form_get_element_by_id (form, element);
+       if (!ZAK_FORM_IS_ELEMENT (priv->message))
+               {
+                       g_warning ("Validator compare: element «%s» isn't a ZakFormElement.", element);
+               }
+}
+
+/**
+ * zak_form_validator_compare_number_get_element_message:
+ * @validator:
+ *
+ * Returns: the validator element name for error message.
+ */
+const gchar
+*zak_form_validator_compare_number_get_element_message (ZakFormValidatorCompareNumber *validator)
+{
+       ZakFormValidatorCompareNumberPrivate *priv = zak_form_validator_compare_number_get_instance_private (validator);
+
+       if (ZAK_FORM_IS_ELEMENT (priv->message))
+               {
+                       return zak_form_element_get_name (priv->message);
+               }
+       else
+               {
+                       return "";
+               }
+}
+
 /* PRIVATE */
 static void
 zak_form_validator_compare_number_set_property (GObject *object,
@@ -354,6 +401,12 @@ zak_form_validator_compare_number_validate (ZakFormValidator *validator)
                                                               zak_form_get_compare_type_stringify (priv->type),
                                                               zak_form_element_get_long_name (priv->v2));
                                        zak_form_validator_set_message (validator, msg);
+
+                                       if (priv->message != NULL)
+                                               {
+                                                       zak_form_element_add_message (priv->message, msg);
+                                               }
+
                                        g_free (msg);
                                }
                }
@@ -374,4 +427,6 @@ zak_form_validator_compare_number_get_xml (ZakFormValidator *validator, xmlNode
        xmlSetProp (xnode, (const xmlChar *)"element1", (const xmlChar *)zak_form_validator_compare_number_get_element1 (validator_compare_number));
 
        xmlSetProp (xnode, (const xmlChar *)"element2", (const xmlChar *)zak_form_validator_compare_number_get_element2 (validator_compare_number));
+
+       xmlSetProp (xnode, (const xmlChar *)"element_message", (const xmlChar *)zak_form_validator_compare_number_get_element_message (validator_compare_number));
 }
index 441954d8deb8e4c509f31ddc40accf29c647083e..d43c119569398f9ce1f8ed4b403160c6e86b634d 100644 (file)
@@ -45,6 +45,9 @@ const gchar *zak_form_validator_compare_number_get_element1 (ZakFormValidatorCom
 void zak_form_validator_compare_number_set_element2 (ZakFormValidatorCompareNumber *validator, ZakFormForm *form, const gchar *element2);
 const gchar *zak_form_validator_compare_number_get_element2 (ZakFormValidatorCompareNumber *validator);
 
+void zak_form_validator_compare_number_set_element_message (ZakFormValidatorCompareNumber *validator, ZakFormForm *form, const gchar *element);
+const gchar *zak_form_validator_compare_number_get_element_message (ZakFormValidatorCompareNumber *validator);
+
 
 G_END_DECLS