From: Andrea Zagli Date: Sun, 16 Apr 2017 11:23:50 +0000 (+0200) Subject: Added function ZakFormElement::get_validator_by_id. X-Git-Tag: v0.1.0~1^2~23 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=d2f714f21b6ee126a2aa338d9fdcc8ab69557a73;p=zakform%2Flibzakform Added function ZakFormElement::get_validator_by_id. --- diff --git a/src/formelement.c b/src/formelement.c index 9e6db5e..bac1f7e 100644 --- a/src/formelement.c +++ b/src/formelement.c @@ -47,17 +47,17 @@ static void zak_form_element_class_init (ZakFormElementClass *class); static void zak_form_element_init (ZakFormElement *zak_form_element); static void zak_form_element_construct (ZakFormElement *element, - const gchar *id, - GHashTable *ht_attrs); + const gchar *id, + GHashTable *ht_attrs); static void zak_form_element_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); + guint property_id, + const GValue *value, + GParamSpec *pspec); static void zak_form_element_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); + guint property_id, + GValue *value, + GParamSpec *pspec); static void zak_form_element_dispose (GObject *gobject); static void zak_form_element_finalize (GObject *gobject); @@ -1100,6 +1100,37 @@ zak_form_element_add_validator (ZakFormElement *element, ZakFormElementValidator g_ptr_array_add (priv->pa_validators, validator); } +/** + * zak_form_element_get_validator_by_id: + * @element: + * @id: + * + */ +ZakFormElementValidator +*zak_form_element_get_validator_by_id (ZakFormElement *element, const gchar *id) +{ + ZakFormElementValidator *validator; + + guint i; + + ZakFormElementPrivate *priv = zak_form_element_get_instance_private (element); + + validator = NULL; + + for (i = 0; i < priv->pa_validators->len; i++) + { + if (g_strcmp0 (zak_form_element_validator_get_id ((ZakFormElementValidator *)g_ptr_array_index (priv->pa_validators, i)), id) == 0) + { + validator = (ZakFormElementValidator *)g_ptr_array_index (priv->pa_validators, i); + break; + } + } + + return validator; + + +} + /** * zak_form_element_is_valid: * @element: diff --git a/src/formelement.h b/src/formelement.h index d68f6a5..bf15098 100644 --- a/src/formelement.h +++ b/src/formelement.h @@ -109,6 +109,7 @@ gboolean zak_form_element_is_valid (ZakFormElement *element); GPtrArray *zak_form_element_get_messages (ZakFormElement *element); GPtrArray *zak_form_element_get_validators (ZakFormElement *element); +ZakFormElementValidator *zak_form_element_get_validator_by_id (ZakFormElement *element, const gchar *id); GPtrArray *zak_form_element_get_validators_by_type (ZakFormElement *element, GType type);