mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Moved is_empty method from field to IPA object
is_empty method represents IPA UI standard of evaluating whether value is empty. Therefore is should be placed in IPA object instead of IPA.field to allow reuse in different locations. https://fedorahosted.org/freeipa/ticket/2351
This commit is contained in:
committed by
Petr Vobornik
parent
25bda1e860
commit
52208e8b40
@@ -1845,8 +1845,8 @@ IPA.dns.netaddr_field = function(spec) {
|
||||
var values = that.field_save();
|
||||
|
||||
//check for empty value: null, [''], '', []
|
||||
var orig_empty = that.is_empty(that.values);
|
||||
var new_empty= that.is_empty(values);
|
||||
var orig_empty = IPA.is_empty(that.values);
|
||||
var new_empty= IPA.is_empty(values);
|
||||
if (orig_empty && new_empty) return false;
|
||||
if (orig_empty != new_empty) return true;
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ IPA.field = function(spec) {
|
||||
|
||||
that.validate_required = function() {
|
||||
var values = that.save();
|
||||
if (that.is_empty(values) && that.is_required() && that.enabled) {
|
||||
if (IPA.is_empty(values) && that.is_required() && that.enabled) {
|
||||
that.valid = false;
|
||||
that.show_error(IPA.messages.widget.validation.required);
|
||||
return false;
|
||||
@@ -123,7 +123,7 @@ IPA.field = function(spec) {
|
||||
|
||||
var values = that.save();
|
||||
|
||||
if (that.is_empty(values)) {
|
||||
if (IPA.is_empty(values)) {
|
||||
return that.valid;
|
||||
}
|
||||
|
||||
@@ -267,8 +267,8 @@ IPA.field = function(spec) {
|
||||
var values = that.save();
|
||||
|
||||
//check for empty value: null, [''], '', []
|
||||
var orig_empty = that.is_empty(that.values);
|
||||
var new_empty= that.is_empty(values);
|
||||
var orig_empty = IPA.is_empty(that.values);
|
||||
var new_empty= IPA.is_empty(values);
|
||||
if (orig_empty && new_empty) return false;
|
||||
if (orig_empty != new_empty) return true;
|
||||
|
||||
@@ -295,22 +295,6 @@ IPA.field = function(spec) {
|
||||
return true;
|
||||
};
|
||||
|
||||
that.is_empty = function(value) {
|
||||
|
||||
var empty = false;
|
||||
|
||||
if (!value) empty = true;
|
||||
|
||||
if (value instanceof Array) {
|
||||
empty = empty || value.length === 0 ||
|
||||
(value.length === 1) && (value[0] === '');
|
||||
}
|
||||
|
||||
if (value === '') empty = true;
|
||||
|
||||
return empty;
|
||||
};
|
||||
|
||||
/**
|
||||
* This function compares the original values and the
|
||||
* values entered in the UI. If the values have changed
|
||||
@@ -560,7 +544,7 @@ IPA.multivalued_field = function(spec) {
|
||||
that.hide_error();
|
||||
that.valid = true;
|
||||
|
||||
if (that.is_empty(values)) {
|
||||
if (IPA.is_empty(values)) {
|
||||
return that.valid;
|
||||
}
|
||||
|
||||
|
||||
@@ -1207,6 +1207,22 @@ IPA.create_options = function(labels, values) {
|
||||
return options;
|
||||
};
|
||||
|
||||
IPA.is_empty = function(value) {
|
||||
|
||||
var empty = false;
|
||||
|
||||
if (!value) empty = true;
|
||||
|
||||
if (value instanceof Array) {
|
||||
empty = empty || value.length === 0 ||
|
||||
(value.length === 1) && (value[0] === '');
|
||||
}
|
||||
|
||||
if (value === '') empty = true;
|
||||
|
||||
return empty;
|
||||
};
|
||||
|
||||
IPA.config = {
|
||||
default_priority: 500
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user