Ticket #595 (enhancement)

Opened 1 year ago

Last modified 1 month ago

ControlCssClass not applied correct if using multiple validators on same control

Status: reopened

Reported by: GoDZilla Assigned to: wei
Priority: normal Milestone: 3.1.3
Component: Prado Framework v3 Version: 3.1
Severity: trivial Keywords: TBaseValidator pdateControlCssClass
Cc:

If a control has more than one validator ControlCssClass? not applied correct if ControlCssClass? contains same css classname.

Maybe i've a quick solution for that problem...but a Prado-Developer should take a look at and run unit-test ;-)

I suggest to modify TBaseValidator::updateControlCssClass()

before:

$class = preg_replace ('/ '.preg_quote($cssClass).'/', '',$control->getCssClass());
if(!$this->getIsValid())
    $class .= ' '.$cssClass;

modified:

$class = preg_replace ('/ '.preg_quote($cssClass).'/', '',$control->getCssClass(), -1, $iCount);
if(!$this->getIsValid() OR $iCount > 0)
    $class .= ' '.$cssClass;

Change History

04/07/2007 05:27:57 PM: Modified by godzilla

On ClientSide?: validator.js Prado.WebUI.TBaseValidator.updateControlCssClass()

before:

if(valid)
  control.removeClassName(CssClass);
else
  control.addClassName(CssClass);

modified:

hasClassName = control.hasClassName(CssClass);
control.removeClassName(CssClass);
if(!valid || hasClassName)
   control.addClassName(CssClass);

04/08/2007 10:13:05 PM: Modified by xue

  • owner changed from xue to wei.
  • version changed from 3.0 to 3.1.

04/08/2007 10:13:30 PM: Modified by xue

  • milestone changed from 3.1 Beta to 3.1 RC.

04/09/2007 09:12:07 AM: Modified by godzilla

my additional comment on clientside validation won't work in all cases :-(

but the following, more complex, modification seems to work

validation3.js

updateControlCssClass : function(control, valid)
	{
		var CssClass = this.options.ControlCssClass;
		if(typeof(CssClass) == "string" && CssClass.length > 0)
		{
			if(!control.validators) control.validators = $H();

			validatorId = this.message.id;

			eval('Item = {' + CssClass + ' : $A()};')

			if(!control.validators.keys().include(CssClass))
				control.validators.merge($H(Item));

			eval('regExp = /' + CssClass + '/;')
			error = control.validators.grep(regExp).first().last();

			if(valid)
				error = error.without(validatorId);
			else
				error.push(validatorId);

			error = error.uniq();

			eval('Item = {' + CssClass + ' : error};')
			control.validators.merge($H(Item));

			if(error.size() == 0)
				control.removeClassName(CssClass);
			else
				control.addClassName(CssClass);
		}
	},

05/08/2007 11:26:11 PM: Modified by wei

  • milestone changed from 3.1 RC to 3.1.0.

this feature

06/25/2007 01:27:27 PM: Modified by xue

  • milestone changed from 3.1.0 to 3.1.1.

09/30/2007 02:16:34 PM: Modified by xue

  • milestone changed from 3.1.1 to 3.1.2.

04/08/2008 09:49:27 AM: Modified by tof06

  • status changed from new to closed.
  • resolution set to fixed.

Thanks to Durgis & Mikl for providing fix and testcase.

04/21/2008 12:12:55 PM: Modified by tof06

  • status changed from closed to reopened.
  • resolution deleted.
  • milestone changed from 3.1.2 to 3.1.3.

Well, it seems that serverside only validators suffer of the same problem.
Let's reopen that for 3.1.3
An idea of implementation

  • Modify IValidatable interface to add a get/setIsValid for each validatable control. This property, defaults to true, will be false if one attached validators fail
  • Modify TBaseValidator::validate to set this property during validation
  • Update TBaseValidator::setCssControlClass method to use this property instead of the result of the current validator.

06/25/2008 06:28:46 AM: Modified by sergeymorkovkin

I confirm. Server-side code fix (suggested by GoDZilla) wasn't applied.