lib/kolab_client_task.php lib/locale public_html/js
Aleksander Machniak
machniak at kolabsys.com
Mon Apr 2 15:28:04 CEST 2012
lib/kolab_client_task.php | 9 ++++++++-
lib/locale/en_US.php | 2 ++
public_html/js/kolab_admin.js | 34 +++++++++++++++++++++++++++++++++-
3 files changed, 43 insertions(+), 2 deletions(-)
New commits:
commit 04a7403fe5e91bf4a4147542f1aa3977d37c3a28
Author: Aleksander Machniak <machniak at kolabsys.com>
Date: Mon Apr 2 15:24:27 2012 +0200
Check required fields on client side
diff --git a/lib/kolab_client_task.php b/lib/kolab_client_task.php
index 1e3acaa..b8f81d3 100644
--- a/lib/kolab_client_task.php
+++ b/lib/kolab_client_task.php
@@ -887,6 +887,7 @@ class kolab_client_task
$form = new kolab_form($attribs);
$assoc_fields = array();
+ $req_fields = array();
// Parse elements and add them to the form object
foreach ($sections as $section_idx => $section) {
@@ -946,6 +947,10 @@ class kolab_client_task
$field['name'] = $idx;
}
+ if (!empty($field['required']) && empty($field['readonly']) && empty($field['disabled'])) {
+ $req_fields[] = $idx;
+ }
+
$form->add_element($field);
}
}
@@ -956,7 +961,7 @@ class kolab_client_task
$form->add_button(array(
'value' => kolab_html::escape($this->translate('submit.button')),
- 'onclick' => $add_mode ? "kadm.{$name}_add()" : "kadm.{$name}_edit()",
+ 'onclick' => "kadm.{$name}_save()",
));
if (!empty($data['id'])) {
@@ -969,6 +974,8 @@ class kolab_client_task
$this->output->set_env('form_id', $attribs['id']);
$this->output->set_env('assoc_fields', $assoc_fields);
+ $this->output->set_env('required_fields', $req_fields);
+ $this->output->add_translation('form.required.empty');
return $form;
}
diff --git a/lib/locale/en_US.php b/lib/locale/en_US.php
index 975dad2..0b70684 100644
--- a/lib/locale/en_US.php
+++ b/lib/locale/en_US.php
@@ -18,6 +18,8 @@ $LANG['login.username'] = 'Username:';
$LANG['login.password'] = 'Password:';
$LANG['login.login'] = 'Login';
+$LANG['form.required.empty'] = 'Some of the required fields are empty!';
+
$LANG['search'] = 'Search';
$LANG['search.criteria'] = 'Search criteria';
$LANG['search.reset'] = 'Reset';
diff --git a/public_html/js/kolab_admin.js b/public_html/js/kolab_admin.js
index 45329be..1f3cdd9 100644
--- a/public_html/js/kolab_admin.js
+++ b/public_html/js/kolab_admin.js
@@ -974,9 +974,31 @@ function kolab_admin()
this.form_error_clear = function()
{
$('input,textarea', $('#'+this.env.form_id)).removeClass('error');
-
}
+ this.check_required_fields = function(data)
+ {
+ var i, n, is_empty, ret = true,
+ req_fields = this.env.required_fields;
+
+ for (i=0; i<req_fields.length; i++) {
+ n = req_fields[i];
+ is_empty = 0;
+
+ if ($.isArray(data[n]))
+ is_empty = data[n].length;
+ else
+ is_empty = !data[n];
+
+ if (is_empty) {
+ this.form_value_error(n);
+ ret = false;
+ }
+ }
+
+ return ret;
+ };
+
/*********************************************************/
/********* Client commands *********/
/*********************************************************/
@@ -1044,6 +1066,11 @@ function kolab_admin()
return;
}
+ if (!this.check_required_fields(data)) {
+ this.display_message('form.required.empty', 'error');
+ return;
+ }
+
this.set_busy(true, 'saving');
this.api_post('user.' + action, data, 'user_' + action + '_response');
};
@@ -1116,6 +1143,11 @@ function kolab_admin()
this.form_error_clear();
+ if (!this.check_required_fields(data)) {
+ this.display_message('form.required.empty', 'error');
+ return;
+ }
+
this.set_busy(true, 'saving');
this.api_post('group.' + action, data, 'group_' + action + '_response');
};
More information about the commits
mailing list