From f3aca177e53b07fa58bea0a26151878bd6cb6d64 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 16 Apr 2017 11:05:10 +0200 Subject: [PATCH] Added ZakForm::get_validator_by_id. --- src/form.c | 30 ++++++++++++++++++++++++++++++ src/form.h | 1 + 2 files changed, 31 insertions(+) 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); -- 2.49.0