From: Andrea Zagli Date: Sun, 16 Apr 2017 09:05:10 +0000 (+0200) Subject: Added ZakForm::get_validator_by_id. X-Git-Tag: v0.1.0~1^2~25 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=f3aca177e53b07fa58bea0a26151878bd6cb6d64;p=zakform%2Flibzakform Added ZakForm::get_validator_by_id. --- diff --git a/src/form.c b/src/form.c index f87771b..181fe1b 100644 --- a/src/form.c +++ b/src/form.c @@ -605,6 +605,36 @@ zak_form_form_add_validator (ZakFormForm *zakform, ZakFormValidator *validator) return ret; } +/** + * zak_form_form_get_validator_by_id: + * @zakform: + * @id: + * + * Returns: a #ZakFormValidator. + */ +ZakFormValidator +*zak_form_form_get_validator_by_id (ZakFormForm *zakform, const gchar *id) +{ + ZakFormValidator *validator; + + guint i; + + ZakFormFormPrivate *priv = zak_form_form_get_instance_private (zakform); + + validator = NULL; + + for (i = 0; i < priv->ar_validators->len; i++) + { + if (g_strcmp0 (zak_form_validator_get_id ((ZakFormValidator *)g_ptr_array_index (priv->ar_validators, i)), id) == 0) + { + validator = (ZakFormValidator *)g_ptr_array_index (priv->ar_validators, i); + break; + } + } + + return validator; +} + /** * zak_form_form_get_validators: * @zakform: diff --git a/src/form.h b/src/form.h index 33b65ea..ee78317 100644 --- a/src/form.h +++ b/src/form.h @@ -54,6 +54,7 @@ GPtrArray *zak_form_form_get_elements (ZakFormForm *zakform); GPtrArray *zak_form_form_get_elements_by_type (ZakFormForm *zakform, GType type); gboolean zak_form_form_add_validator (ZakFormForm *zakform, ZakFormValidator *validator); +ZakFormValidator *zak_form_form_get_validator_by_id (ZakFormForm *zakform, const gchar *id); GPtrArray *zak_form_form_get_validators (ZakFormForm *zakform); GPtrArray *zak_form_form_get_validators_by_type (ZakFormForm *zakform, GType type);