On 07/07/2011 04:46 PM, Adam Young wrote:
No longer testing on blur, as it was causing to many issues. Now
checking upon click of the add button.
On 07/07/2011 12:05 AM, Endi Sukma Dewata wrote:
On 7/6/2011 7:56 PM, Adam Young wrote:
1. The check_required() is only called in blur events. It's not
called on Add/Update.
Fixed. Looks like this works even for checkboxes.
There seems to be a race condition. Open the group adder dialog, then
click Add. Sometimes only group name gets an error, sometimes the
description too. It looks like there are 2 events happening at the
same time: input blur and button click, and both are modifying the
valid attribute and the error message.
Another problem, open the group adder dialog, then click Cancel.
You'll get an error and the dialog doesn't close. Is blur really a
good place to check required?
Which checkboxes are you referring to? The IPA.attribute_widget is a
subclass of IPA.checkboxes_widget, but it doesn't seem to check
required.
2. In IPA.entity_select_widget the check_required() is only called if
the widget is editable.
To test, open IPA Server -> Configuration, set the Default user group
to empty, then click somewhere else. There's no validation error.
Fixed, but I don't think that there is currently a testable case for
this, as many things don't have required set.
This can be verified with the above scenario by setting the
ipadefaultprimarygroup to required in ipa_init.json (it should have
been required anyway). There's a problem, the entity_link is only
created when the widget is editable.
3. Also in IPA.entity_select_widget the check_required() is only
called from the text input's blur event, not from the drop down list.
This leads to strange behavior:
Open the hosts' adder dialog, click the drop down list, the
validation error will appear before the user has a chance to select a
value.
Again fixed ,but not sure it is verifiable. host and service add don't
seem to have metadata for required.
This can be verified with the above scenario. The host's fqdn is
required. The problem still exists.
4. For consistency, the multivalued_text and textarea widgets can be
modified to call the create_error_link() to create the error_link
element.
done
The IPA.multivalued_text_widget is still creating it's own error_link.
_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel
From b34ff2ec41e1b10e29711bca60d9acdd74f30c04 Mon Sep 17 00:00:00 2001
From: Adam Young <[email protected]>
Date: Wed, 6 Jul 2011 15:43:50 -0400
Subject: [PATCH] check required on add
previsouly was checked on key down, but that does the check too soon.
Next attempt was on blur, but that had numerous problems. This now checkes when the add button is clicked.
works for entity_select widget, too
Checks upon form submission
https://fedorahosted.org/freeipa/ticket/1437
---
install/ui/add.js | 11 ++++++-
install/ui/service.js | 1 +
install/ui/widget.js | 77 +++++++++++++++++++++++++------------------------
3 files changed, 49 insertions(+), 40 deletions(-)
diff --git a/install/ui/add.js b/install/ui/add.js
index 50b6124c094c60f18c32897da603331db8c6a161..0a414b74b181e8d20fd80594a00f93b25c688f6e 100644
--- a/install/ui/add.js
+++ b/install/ui/add.js
@@ -118,11 +118,14 @@ IPA.add_dialog = function (spec) {
for (var i=0; i<fields.length; i++) {
fields[i].validate();
}
-
+ var required_fields_filled = true;
for (i=0; i<fields.length; i++) {
field = fields[i];
if (!field.valid) return;
+ required_fields_filled = field.check_required() &&
+ required_fields_filled;
+
value = record[field.name];
if (!value) continue;
@@ -141,6 +144,8 @@ IPA.add_dialog = function (spec) {
for (var k=0; k<section_fields.length; k++) {
field = section_fields[k];
if (!field.valid) return;
+ required_fields_filled = field.check_required() &&
+ required_fields_filled;
value = record[field.name];
if (!value) continue;
@@ -155,7 +160,9 @@ IPA.add_dialog = function (spec) {
//alert(JSON.stringify(command.to_json()));
- command.execute();
+ if (required_fields_filled){
+ command.execute();
+ }
};
that.add_dialog_init = that.init;
diff --git a/install/ui/service.js b/install/ui/service.js
index 6fcd4348236c1b13e296cdd8a1a9b1a25c486134..943995a22298906ca9d2d970d53aabf61c21aa71 100644
--- a/install/ui/service.js
+++ b/install/ui/service.js
@@ -110,6 +110,7 @@ IPA.service_add_dialog = function(spec) {
var that = IPA.add_dialog(spec).
field(IPA.widget({
name: 'krbprincipalname',
+ optional:true,
hidden: true
})).
field(IPA.service_select_widget({
diff --git a/install/ui/widget.js b/install/ui/widget.js
index 9142a26a90927ecaa845c25b80f94f6938209f12..0ec9a968bf5415d3f21fd2d0a2d8cb01eec64797 100644
--- a/install/ui/widget.js
+++ b/install/ui/widget.js
@@ -107,27 +107,39 @@ IPA.widget = function(spec) {
}
}
+ that.create_error_link = function(container){
+ container.append(' ');
+
+ $('<span/>', {
+ name: 'error_link',
+ html: IPA.messages.widget.validation.error,
+ 'class': 'ui-state-error ui-corner-all',
+ style: 'display:none'
+ }).appendTo(container);
+ };
+
+ that.check_required = function(){
+ var values = that.save();
+ if (!values || !values.length || values[0] === '' ) {
+ if (that.param_info &&
+ that.param_info.required &&
+ !that.optional) {
+ that.valid = false;
+ that.show_error(IPA.messages.widget.validation.required);
+ return false;
+ }
+ }
+ return true;
+ };
/*returns true and clears the error message if the field value passes
the validation pattern. If the field value does not pass validation,
displays the error message and returns false. */
that.validate = function() {
-
- that.hide_error();
-
+ hide_error();
that.valid = true;
var values = that.save();
- if (!values || !values.length) {
- if (that.param_info &&
- that.param_info.required &&
- !that.optional) {
- that.valid = false;
- that.show_error(IPA.messages.widget.validation.required);
- }
- return;
- }
-
var value = values[0];
if (!value) {
return;
@@ -319,10 +331,10 @@ IPA.widget = function(spec) {
error_link.css('display', 'block');
};
- that.hide_error = function() {
+ function hide_error() {
var error_link = that.get_error_link();
error_link.css('display', 'none');
- };
+ }
that.set_enabled = function() {
};
@@ -371,6 +383,7 @@ IPA.text_widget = function(spec) {
IPA.select_range(that.input, start, end);
};
+
that.create = function(container) {
$('<label/>', {
@@ -391,14 +404,7 @@ IPA.text_widget = function(spec) {
that.create_undo(container);
}
- container.append(' ');
-
- $('<span/>', {
- name: 'error_link',
- html: IPA.messages.widget.validation.error,
- 'class': 'ui-state-error ui-corner-all',
- style: 'display:none'
- }).appendTo(container);
+ that.create_error_link(container);
};
that.setup = function(container) {
@@ -546,14 +552,7 @@ IPA.multivalued_text_widget = function(spec) {
that.create_undo(div);
}
- div.append(' ');
-
- $('<span/>', {
- name: 'error_link',
- html: IPA.messages.widget.validation.error,
- 'class': 'ui-state-error ui-corner-all',
- style: 'display:none'
- }).appendTo(div);
+ that.create_error_link(container);
$('<a/>', {
name: 'add',
@@ -1079,12 +1078,8 @@ IPA.textarea_widget = function (spec) {
that.create_undo(container);
}
- $("<span/>",{
- name:'error_link',
- html: IPA.messages.widget.validation.error,
- "class":"ui-state-error ui-corner-all",
- style:"display:none"
- }).appendTo(container);
+ that.create_error_link(container);
+
};
that.setup = function(container) {
@@ -1650,7 +1645,10 @@ IPA.entity_select_widget = function(spec) {
if (editable){
that.edit_box = $('<input />',{
type: 'text',
- title: that.tooltip
+ title: that.tooltip,
+ keyup:function(){
+ that.validate();
+ }
});
$('<div style:"display=block;" />').
@@ -1658,9 +1656,12 @@ IPA.entity_select_widget = function(spec) {
appendTo(container);
}
+ that.create_error_link(container);
+
that.entity_select = $('<select/>', {
id: that.name + '-entity-select',
change: function(){
+ that.validate();
if (editable){
that.edit_box.val(
$('option:selected', that.entity_select).val());
--
1.7.5.2
_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel