Merge pull request #91 from brayanpereyra/BUG-9327
Bug 9327 Don't validate required field in grid SOLVED
This commit is contained in:
@@ -2550,10 +2550,9 @@ var validateGridForms = function(invalidFields){
|
||||
|
||||
for(j=0; j<grids.length; j++){
|
||||
|
||||
// check all the input fields in the grid
|
||||
fields = grids[j].getElementsByTagName('input');
|
||||
// labels = ;
|
||||
for(i=0; i<fields.length; i++){
|
||||
var vtext = new input(fields[i]);
|
||||
if (fields[i].getAttribute("pm:required")=="1"&&fields[i].value==''){
|
||||
$label = fields[i].name.split("[");
|
||||
$labelPM = fields[i].getAttribute("pm:label");
|
||||
@@ -2563,32 +2562,51 @@ var validateGridForms = function(invalidFields){
|
||||
$fieldName = $labelPM + " " + $label[2].split("]")[0];
|
||||
}
|
||||
fieldGridName = $label[1] + "[" + $label[2] + "[" + $label[3].split("]")[0];
|
||||
//$fieldName = labels[i].innerHTML.replace('*','') + " " + $label[2].split("]")[0];
|
||||
|
||||
if (!notValidateThisFields.inArray(fieldGridName))
|
||||
if (!notValidateThisFields.inArray(fieldGridName)) {
|
||||
invalidFields.push($fieldName);
|
||||
}
|
||||
|
||||
vtext.failed();
|
||||
} else {
|
||||
vtext.passed();
|
||||
}
|
||||
}
|
||||
|
||||
textAreas = grids[j].getElementsByTagName('textarea');
|
||||
for(i=0; i<textAreas.length; i++){
|
||||
var vtext = new input(textAreas[i]);
|
||||
if (textAreas[i].getAttribute("pm:required")=="1"&&textAreas[i].value==''){
|
||||
$label = textAreas[i].name.split("[");
|
||||
$fieldName = $label[3].split("]")[0]+ " " + $label[2].split("]")[0];
|
||||
fieldGridName = $label[1] + "[" + $label[2] + "[" + $label[3].split("]")[0];
|
||||
if (!notValidateThisFields.inArray(fieldGridName))
|
||||
|
||||
if (!notValidateThisFields.inArray(fieldGridName)) {
|
||||
invalidFields.push($fieldName);
|
||||
}
|
||||
|
||||
vtext.failed();
|
||||
} else {
|
||||
vtext.passed();
|
||||
}
|
||||
}
|
||||
|
||||
dropdowns = grids[j].getElementsByTagName('select');
|
||||
for(i=0; i<dropdowns.length; i++){
|
||||
var vtext = new input(dropdowns[i]);
|
||||
|
||||
if (dropdowns[i].getAttribute("pm:required")=="1"&&dropdowns[i].value==''){
|
||||
$label = dropdowns[i].name.split("[");
|
||||
$fieldName = $label[3].split("]")[0]+ " " + $label[2].split("]")[0];
|
||||
fieldGridName = $label[1] + "[" + $label[2] + "[" + $label[3].split("]")[0];
|
||||
if (!notValidateThisFields.inArray(fieldGridName))
|
||||
|
||||
if (!notValidateThisFields.inArray(fieldGridName)) {
|
||||
invalidFields.push($fieldName);
|
||||
}
|
||||
|
||||
vtext.failed();
|
||||
} else {
|
||||
vtext.passed();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2606,6 +2624,86 @@ var validateGridForms = function(invalidFields){
|
||||
**/
|
||||
|
||||
var validateForm = function(sRequiredFields) {
|
||||
// The code add Brayan Pereyra - Cochalo :
|
||||
// This part add to firefox 13 and ie 9, in event submit the object leminud and input disappeared
|
||||
if (typeof(leimnud) == 'undefined') {
|
||||
var leimnud = new maborak();
|
||||
leimnud.make({
|
||||
zip:true,
|
||||
inGulliver:true,
|
||||
modules :"dom,abbr,rpc,drag,drop,app,panel,fx,grid,xmlform,validator,dashboard",
|
||||
files :""
|
||||
});
|
||||
}
|
||||
|
||||
// The code add Brayan Pereyra - Cochalo :
|
||||
// This part add to firefox 13 and ie 9, in event submit the object leminud and input disappeared
|
||||
if (typeof(input) == 'undefined') {
|
||||
var input = function(options)
|
||||
{
|
||||
this.make=function(options)
|
||||
{
|
||||
this.input = (options && options.tagName)?$(options):(new this.parent.module.dom.create("input",{
|
||||
className:"module_app_input___gray",
|
||||
type :"text",
|
||||
value :options.label || "",
|
||||
maxLength :options.maxlength || "30"
|
||||
}.concat(options.properties || {}),(options.style || {})));
|
||||
|
||||
this.input.disable=function()
|
||||
{
|
||||
this.input.disabled=true;
|
||||
this.input.className=this.input.className+" module_app_inputDisabled___gray";
|
||||
return this.input;
|
||||
}.extend(this);
|
||||
this.input.enable=function()
|
||||
{
|
||||
this.input.disabled=false;
|
||||
this.input.className=this.input.className.split(" ")[0];
|
||||
return this.input;
|
||||
}.extend(this);
|
||||
this.input.passed=function()
|
||||
{
|
||||
if ('\v'=='v') { //verify if is internet explorer
|
||||
this.input.className="module_app_inputPassed_ie___gray "+((this.input.className.split(' ')[1]) || '');
|
||||
} else {
|
||||
this.input.className="module_app_inputPassed___gray "+((this.input.className.split(' ')[1]) || '');
|
||||
}
|
||||
return this.input;
|
||||
}.extend(this);
|
||||
this.input.normal=function()
|
||||
{
|
||||
this.input.className=this.input.className+" "+((this.input.className.split(' ')[1]) || '');
|
||||
return this.input;
|
||||
}.extend(this);
|
||||
this.input.failed=function()
|
||||
{
|
||||
if ('\v'=='v') { //verify if is internet explorer
|
||||
this.input.className="module_app_inputFailed_ie___gray "+((this.input.className.split(' ')[1]) || '');
|
||||
} else {
|
||||
this.input.className="module_app_inputFailed___gray "+((this.input.className.split(' ')[1]) || '');
|
||||
}
|
||||
|
||||
return this.input;
|
||||
}.extend(this);
|
||||
|
||||
return this.input;
|
||||
};
|
||||
this.mouseover=function()
|
||||
{
|
||||
this.input.className="module_app_input___gray module_app_inputHover___gray";
|
||||
return false;
|
||||
};
|
||||
this.mouseout=function()
|
||||
{
|
||||
this.input.className="module_app_input___gray";
|
||||
return false;
|
||||
};
|
||||
this.expand();
|
||||
return this.make(options || {});
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* replacing the %27 code by " character (if exists), this solve the problem that " broke the properties definition into a html
|
||||
* i.ei <form onsubmit="myaction(MyjsString)" ... with var MyjsString = "some string that is into a variable, so this broke the html";
|
||||
@@ -2620,10 +2718,9 @@ var validateForm = function(sRequiredFields) {
|
||||
aRequiredFields = eval(sRequiredFields);
|
||||
|
||||
var sMessage = '';
|
||||
var invalid_fields = Array();
|
||||
|
||||
var fielEmailInvalid = Array();
|
||||
|
||||
var invalid_fields = Array();
|
||||
var fielEmailInvalid = Array();
|
||||
|
||||
for (var i = 0; i < aRequiredFields.length; i++) {
|
||||
aRequiredFields[i].label=(aRequiredFields[i].label=='')?aRequiredFields[i].name:aRequiredFields[i].label;
|
||||
|
||||
@@ -2825,6 +2922,7 @@ var validateForm = function(sRequiredFields) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// call added by gustavo - cruz, gustavo-at-colosa.com validate grid forms
|
||||
invalid_fields = validateGridForms(invalid_fields);
|
||||
|
||||
|
||||
@@ -509,12 +509,30 @@ class Form extends XmlForm
|
||||
*/
|
||||
function validateRequiredFields($dataFields, $noRequired = array())
|
||||
{
|
||||
$requiredFields = array();
|
||||
$requiredFields = array();
|
||||
$notPassedFields = array();
|
||||
$skippedFieldsTypes = array('javascript', 'checkbox', 'yesno', 'submit', 'button', 'title', 'subtitle',
|
||||
'button', 'submit', 'reset', 'hidden', 'link');
|
||||
$requiredFieldsGrids = array();
|
||||
$grids = array();
|
||||
|
||||
foreach ($this->fields as $field) {
|
||||
// verify fields in grids
|
||||
if($field->type == 'grid') {
|
||||
array_push($grids, $field->name);
|
||||
foreach ($field->fields as $fieldGrid) {
|
||||
if (is_object($fieldGrid) && isset($fieldGrid->required) && $fieldGrid->required) {
|
||||
if (!in_array($fieldGrid->type, $skippedFieldsTypes)) {
|
||||
if ( !(is_array($requiredFieldsGrids[$field->name])) ) {
|
||||
$requiredFieldsGrids[$field->name] = array();
|
||||
}
|
||||
array_push($requiredFieldsGrids[$field->name], $fieldGrid->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// verify fields the form
|
||||
if (is_object($field) && isset($field->required) && $field->required) {
|
||||
if (!in_array($field->type, $skippedFieldsTypes)) {
|
||||
array_push($requiredFields, $field->name);
|
||||
@@ -523,12 +541,25 @@ class Form extends XmlForm
|
||||
}
|
||||
|
||||
foreach($dataFields as $dataFieldName => $dataField) {
|
||||
if (in_array($dataFieldName, $grids)) {
|
||||
foreach ($dataField as $indexGrid => $dataGrid) {
|
||||
foreach ($dataGrid as $fieldGridName => $fieldGridValue) {
|
||||
if (in_array($fieldGridName, $requiredFieldsGrids[$dataFieldName]) && !in_array($fieldGridName, $noRequired) && trim($fieldGridValue) == '') {
|
||||
if ( !(is_array($notPassedFields[$dataFieldName])) ) {
|
||||
$notPassedFields[$dataFieldName] = array();
|
||||
}
|
||||
$notPassedFields[$dataFieldName][$indexGrid][] = $fieldGridName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//verify if the requiered field is in $requiredFields array
|
||||
if (in_array($dataFieldName, $requiredFields) && !in_array($dataFieldName, $noRequired) && trim($dataField) == '') {
|
||||
$notPassedFields[] = $dataFieldName;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return count($notPassedFields) > 0 ? $notPassedFields : false;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
|
||||
|
||||
$width_content = '430px';
|
||||
$width_content = '500px';
|
||||
|
||||
$html = '
|
||||
<div class="boxTopBlue"><div class="a"></div><div class="b"></div><div class="c"></div></div>
|
||||
@@ -46,12 +46,26 @@
|
||||
<div class="boxBottomBlue"><div class="a"></div><div class="b"></div><div class="c"></div></div>';
|
||||
|
||||
$rq = $_POST['req_val'];
|
||||
foreach( $rq as $field) {
|
||||
$html .= "<table width='100%' cellspacing='0' cellpadding='0' border='1' style='border:0px;'>
|
||||
foreach( $rq as $indexRq => $field) {
|
||||
if ( is_array($field) ) {
|
||||
foreach ($field as $row => $fieldsRow) {
|
||||
foreach ($fieldsRow as $fieldGrid) {
|
||||
$html .= "<table width='100%' cellspacing='0' cellpadding='0' border='1' style='border:0px;'>
|
||||
<tr><td width='300px' class='treeNode' style='border:0px;background-color:transparent;'>
|
||||
<font color=black>(*) The field <font color=blue><b>$fieldGrid</b></font> of the row
|
||||
<font color=blue><b>$row</b></font> in the grid
|
||||
<font color=blue><b>$indexRq</b></font> is required!</font>
|
||||
</td></tr>
|
||||
</table> ";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$html .= "<table width='100%' cellspacing='0' cellpadding='0' border='1' style='border:0px;'>
|
||||
<tr><td width='300px' class='treeNode' style='border:0px;background-color:transparent;'>
|
||||
<font color=black>(*) The field <font color=blue><b>$field</b></font> is required!</font>
|
||||
</td></tr>
|
||||
</table> ";
|
||||
}
|
||||
}
|
||||
|
||||
$netxpage = $_POST['next_step']['PAGE'];
|
||||
@@ -65,7 +79,7 @@
|
||||
echo '<div class="grid" style="width:'.$width_content.'">
|
||||
<div class="boxTop"><div class="a"></div><div class="b"></div><div class="c"></div></div>
|
||||
<div class="content" style="">
|
||||
<table >
|
||||
<table width="490px">
|
||||
<tbody><tr>
|
||||
<td valign="top">
|
||||
'.$html.'
|
||||
|
||||
Reference in New Issue
Block a user