Support several sets of forbidden values (with a specific "reason" message) per field.

SVN:trunk[3500]
This commit is contained in:
Denis Flaven
2015-03-10 15:34:04 +00:00
parent d575c48579
commit f7c7fc5dc4
2 changed files with 14 additions and 15 deletions

View File

@@ -867,13 +867,11 @@ class DesignerTextField extends DesignerFormField
{
protected $sValidationPattern;
protected $aForbiddenValues;
protected $sExplainForbiddenValues;
public function __construct($sCode, $sLabel = '', $defaultValue = '')
{
parent::__construct($sCode, $sLabel, $defaultValue);
$this->sValidationPattern = '';
$this->aForbiddenValues = null;
$this->sExplainForbiddenValues = null;
$this->aForbiddenValues = array();
}
public function SetValidationPattern($sValidationPattern)
@@ -883,17 +881,17 @@ class DesignerTextField extends DesignerFormField
public function SetForbiddenValues($aValues, $sExplain)
{
$this->aForbiddenValues = $aValues;
$aForbiddenValues = $aValues;
$iDefaultKey = array_search($this->defaultValue, $this->aForbiddenValues);
if ($iDefaultKey !== false)
{
// The default (current) value is always allowed...
unset($this->aForbiddenValues[$iDefaultKey]);
unset($aForbiddenValues[$iDefaultKey]);
}
$this->sExplainForbiddenValues = $sExplain;
$this->aForbiddenValues[] = array('values' => $aForbiddenValues, 'message' => $sExplain);
}
public function Render(WebPage $oP, $sFormId, $sRenderMode='dialog')
@@ -911,17 +909,15 @@ class DesignerTextField extends DesignerFormField
if (is_array($this->aForbiddenValues))
{
$sForbiddenValues = json_encode($this->aForbiddenValues);
$sExplainForbiddenValues = addslashes($this->sExplainForbiddenValues);
}
else
{
$sForbiddenValues = 'null';
$sExplainForbiddenValues = 'null';
$sForbiddenValues = '[]'; //Empty JS array
}
$sMandatory = $this->bMandatory ? 'true' : 'false';
$oP->add_ready_script(
<<<EOF
$('#$sId').bind('change keyup validate', function() { ValidateWithPattern('$sId', $sMandatory, '$sPattern', $(this).closest('form').attr('id'), $sForbiddenValues, '$sExplainForbiddenValues'); } );
$('#$sId').bind('change keyup validate', function() { ValidateWithPattern('$sId', $sMandatory, '$sPattern', $(this).closest('form').attr('id'), $sForbiddenValues); } );
{
var myTimer = null;
$('#$sId').bind('keyup', function() { clearTimeout(myTimer); myTimer = setTimeout(function() { $('#$sId').trigger('change', {} ); }, 100); });