Pārlūkot izejas kodu

Support for Date and DateTime in portal
Fixed form validation on portal

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4025 a333f486-631f-4898-b8df-5754b55c2be0

glajarige 9 gadi atpakaļ
vecāks
revīzija
4000bb5608

+ 8 - 6
js/form_field.js

@@ -122,7 +122,6 @@ $(function()
 			// Doing data validation
 			if(this.options.validators !== null)
 			{
-				var bMandatory = (this.options.validators.mandatory !== undefined);
 				// Extracting value for the field
 				var oValue = this.element.triggerHandler('get_current_value');
 				if(oValue === null)
@@ -130,19 +129,22 @@ $(function()
 					console.log('Form field : Warning, there was no value for "'+this.element.attr('data-field-id')+'"');
 					return oResult;
 				}
-				var aValueKeys = Object.keys(oValue);
+				
+				var bMandatory = (this.options.validators.mandatory !== undefined);
+				var bEmpty = ($.isArray(oValue)) ? (oValue.length === 0) : (oValue === '' || oValue === undefined);
+				var value = oValue;
 				
 				// This is just a safety check in case a field doesn't always return an object when no value assigned, so we have to check the mandatory validator here...
 				// ... But this should never happen.
-				if( (aValueKeys.length === 0) && bMandatory )
+				//if( (aValueKeys.length === 0) && bMandatory )
+				if( bEmpty && bMandatory )
 				{
 					oResult.is_valid = false;
 					oResult.error_messages.push(this.options.validators.mandatory.message);
 				}
 				// ... Otherwise, we check every validators
-				else if(aValueKeys.length > 0)
+				else
 				{
-					var value = oValue[aValueKeys[0]];
 					for(var sValidatorType in this.options.validators)
 					{
 						var oValidator = this.options.validators[sValidatorType];
@@ -186,7 +188,7 @@ $(function()
 								}
 							}
 							else if($.isArray(value))
-							{
+							{	
 								for(var i in value)
 								{
 									if(value[i] === 'string' && !oRegExp.test(value))

+ 1 - 1
sources/renderer/bootstrap/fieldrenderer/bslinkedsetfieldrenderer.class.inc.php

@@ -86,7 +86,7 @@ EOF
 
 			// Rendering table widget
 			// - Vars
-			$sEmptyTableLabel = htmlentities(Dict::S('UI:Message:EmptyList:UseAdd'), ENT_QUOTES, 'UTF-8');
+			$sEmptyTableLabel = htmlentities(Dict::S( ($this->oField->GetReadOnly()) ? 'Portal:Datatables:Language:EmptyTable' : 'UI:Message:EmptyList:UseAdd'), ENT_QUOTES, 'UTF-8');
 			$sSelectionOptionHtml = ($this->oField->GetReadOnly()) ? 'false' : '{"style": "multi"}';
 			$sSelectionInputHtml = ($this->oField->GetReadOnly()) ? '' : '<span class="row_input"><input type="checkbox" name="' . $this->oField->GetId() . '" /></span>';
 			// - Output

+ 1 - 1
sources/renderer/bootstrap/fieldrenderer/bssimplefieldrenderer.class.inc.php

@@ -166,7 +166,7 @@ EOF
 					{
 						// Note : The test is a double equal on purpose as the type of the value received from the XHR is not always the same as the type of the allowed values. (eg : string vs int)
 						$sSelectedAtt = ($this->oField->GetCurrentValue() == $sChoice) ? 'selected' : '';
-						$oOutput->AddHtml('<option value="' . $sChoice . '" ' . $sSelectedAtt . ' >')->AddHtml($sLabel, true)->AddHtml('</option>');
+						$oOutput->AddHtml('<option value="' . $sChoice . '" ' . $sSelectedAtt . ' >')->AddHtml($sLabel)->AddHtml('</option>');
 					}
 					$oOutput->AddHtml('</select>');
 					$oOutput->AddHtml('</div>');