ZakFormElementValidator *validator = (ZakFormElementValidator *)g_ptr_array_index (priv->pa_validators, i);
if (!zak_form_element_validator_validate (validator, value))
{
- g_ptr_array_add (priv->pa_messages, (gpointer)g_strdup (zak_form_element_validator_get_message (validator)));
+ zak_form_element_add_message (element, (const gchar *)g_strdup (zak_form_element_validator_get_message (validator)));
ret = FALSE;
}
void
zak_form_element_set_messages (ZakFormElement *element, GPtrArray *messages)
{
+ guint i;
+
ZakFormElementPrivate *priv = zak_form_element_get_instance_private (element);
if (priv->pa_messages != NULL)
{
g_ptr_array_free (priv->pa_messages, TRUE);
- priv->pa_messages = copy_ar_func (messages);
+ }
+
+ if (messages == NULL)
+ {
+ return;
+ }
+
+ priv->pa_messages = g_ptr_array_new ();
+
+ for (i = 0; i < messages->len; i++)
+ {
+ zak_form_element_add_message (element, (const gchar *)g_strdup ((gchar *)g_ptr_array_index (messages, i)));
+ }
+}
+
+/**
+ * zak_form_element_add_message:
+ * @element:
+ * @message:
+ *
+ * Add an element's message.
+ */
+void
+zak_form_element_add_message (ZakFormElement *element, const gchar *message)
+{
+ ZakFormElementPrivate *priv = zak_form_element_get_instance_private (element);
+
+ if (priv->pa_messages == NULL)
+ {
+ priv->pa_messages = g_ptr_array_new ();
+ }
+
+ /* check duplicate */
+ if (!g_ptr_array_find_with_equal_func (priv->pa_messages,
+ message,
+ g_str_equal,
+ NULL))
+ {
+ g_ptr_array_add (priv->pa_messages, (gpointer)g_strdup (message));
}
}
gboolean zak_form_element_is_valid (ZakFormElement *element);
GPtrArray *zak_form_element_get_messages (ZakFormElement *element);
void zak_form_element_set_messages (ZakFormElement *element, GPtrArray *messages);
+void zak_form_element_add_message (ZakFormElement *element, const gchar *message);
GPtrArray *zak_form_element_get_validators (ZakFormElement *element);
ZakFormElementValidator *zak_form_element_get_validator_by_id (ZakFormElement *element, const gchar *id);