Commit 74ffaddf authored by Jerome Mariette's avatar Jerome Mariette
Browse files

fixe a bug with required / required+exclude

parent b6793e55
......@@ -89,23 +89,34 @@
errorClass: "error"
});
jQuery.validator.addMethod("exlude", function(value, element, options) {
jQuery.validator.addMethod("exclude", function(value, element, options) {
var validator = this,
selector = options;
var numberFilled = $(selector, element.form).filter(function() {
return validator.elementValue(this);
}).length;
var valid = numberFilled === 1;
if(!$(element).data('being_validated')) {
var fields = $(selector, element.form);
fields.data('being_validated', true);
fields.valid();
fields.data('being_validated', false);
var valid = false;
if (numberFilled === 1) {
valid = true;
} else if (numberFilled === 0) {
valid = true;
}
return valid;
}, jQuery.format("Please fill only one of these fields."));
jQuery.validator.addMethod("exclude_required", function(value, element, options) {
var validator = this,
selector = options;
var numberFilled = $(selector, element.form).filter(function() {
return validator.elementValue(this);
}).length;
var valid = false;
if (numberFilled === 1) {
valid = true;
}
return valid;
}, jQuery.format("Please fill one and only one of these fields."));
!function ($) {
"use strict"; // jshint ;_;
......@@ -194,18 +205,25 @@ jQuery.validator.addMethod("exlude", function(value, element, options) {
$.tmpl($this.options.template, {workflow: $this.workflow, display_run_button: $this.options.displayRunButton,
display_reset_button: $this.options.displayResetButton, parameters: $this.options.parameters,
getParameterDisplay:$this._getParameterDisplay, parameterTemplate: $this.options.parameterTemplate}).appendTo($this.$element);
$('.date').datepicker().on('changeDate', function(ev){ $('.date').datepicker('hide');} );
$('.date').datepicker().on('changeDate', function(ev){ $('.date').datepicker('hide');} );
// for exclude-required first check if there is no exclusion group with a required option
var excludereq = new Array();
for (var i in $this.workflow.parameters) {
if ($this.workflow.parameters[i].group.indexOf("exclude-") != -1 && $this.workflow.parameters[i].required) {
if (excludereq.indexOf($this.workflow.parameters[i].group) == -1) {
excludereq.push($this.workflow.parameters[i].group);
}
}
}
for (var i in $this.workflow.parameters) {
// if it's a multiple parameter add its sub parameters as rules
if ($this.workflow.parameters[i].type == "MultipleParameters") {
for (var j in $this.workflow.parameters[i].sub_parameters) {
rules[$this.workflow.parameters[i].sub_parameters[j].name] = $this._getParameterRule($this.workflow.parameters[i].sub_parameters[j], $this.options.serverURL);
rules[$this.workflow.parameters[i].sub_parameters[j].name] = $this._getParameterRule($this.workflow.parameters[i].sub_parameters[j], $this.options.serverURL, excludereq);
}
} else {
rules[$this.workflow.parameters[i].name] = $this._getParameterRule($this.workflow.parameters[i], $this.options.serverURL);
}
if ($this.workflow.parameters[i].group.indexOf("exclude-") != -1) {
rules[$this.workflow.parameters[i].name]["exlude"] = "."+$this.workflow.parameters[i].group;
rules[$this.workflow.parameters[i].name] = $this._getParameterRule($this.workflow.parameters[i], $this.options.serverURL, excludereq);
}
}
$("#workflow_form").validate({ rules: rules });
......@@ -219,34 +237,32 @@ jQuery.validator.addMethod("exlude", function(value, element, options) {
});
}
WFForm.prototype._getParameterRule = function(param, server_url) {
WFForm.prototype._getParameterRule = function(param, server_url, excludereq) {
var crule = {};
if (param.type == "int") {
return {
required: param.required,
number: true
}
crule["number"] = true;
} else if (param.type == "date") {
return {
required: param.required,
date: true
}
} else if (param.type == "str") {
return {
required: param.required
}
crule["date"] = true;
// if it is not a known type, check from the custom ones, using the validate_field address
} else {
return {
required: param.required,
remote: {
url: server_url + '/validate_field?callback=?',
type: "post",
data: {
type: param.type
}
}
}
crule["remote"] = {
url: server_url + '/validate_field?callback=?',
type: "post",
data: {
type: param.type
}
};
}
if (excludereq.indexOf(param.group) != -1) {
crule["exclude_required"] = "."+param.group;
crule["required"] = false;
} else if (param.group.indexOf("exclude-") != -1) {
crule["exclude"] = "."+param.group;
crule["required"] = false;
} else {
crule["required"] = param.required;
}
return crule;
}
WFForm.prototype._getParameterDisplay = function(param, template, input_size, check_title) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment