?
avatar Devportobello
Devportobello
4 Feb 2015

To reproduce the issue

Setup JForm XML form with a group + use field to validate equals:
ex:

<?xml version="1.0" encoding="utf-8"?>
<form>
  <fields name="example">
   <field name="name" type="text" ... />
    <field name="password" type="password"
      autocomplete="off"
      class="validate-password"
      description="DESIRED_PASSWORD"
      field="password"
      filter="raw"
      label="PASSWORD_LABEL"
      size="10"
      validate="password"
      required="true"
    />
    <field name="password2" type="password"
      autocomplete="off"
      class="validate-password"
      description="PASSWORD2_DESC"
      field="password"
      filter="raw"
      label="PASSWORD2_LABEL"
      message="PASSWORD1_MESSAGE"
      size="30"
      validate="equals"
      required="true"
    />
 </fields>
</form>

Expected result

Comparing password fields when password == password2 return true

Actual result

Comparing password fields dont return true if password == password2

System information

Joomla : 3.3.6 Stable [ Ember ] 01-October-2014 02:00 GMT
PHP : 5.5.12
Apache : 2.4.9

Additional comments

Group are not taked into account when comparing value of those fields

Code to resolve \libraries\joomla\form\rule\equals.php JFormRuleEquals

// Method to test if two values are equal. To use this rule, the form
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
{
    $field = (string) $element['field'];

    // Check that a validation field is set.
    if (!$field)
    {
        throw new UnexpectedValueException(sprintf('$field empty in %s::test', get_class($this)));
    }

    if (is_null($form))
    {
        throw new InvalidArgumentException(sprintf('The value for $form must not be null in %s', get_class($this)));
    }

    if (is_null($input))
    {
        throw new InvalidArgumentException(sprintf('The value for $input must not be null in %s', get_class($this)));
    }

    // HERE i added conditionnal to take account of group
    if(isset($group))
    {
        $test = $input->get($group.'.'.$field);
    }
    else
    {
        $test = $input->get($field);
    }

    // Test the two values against each other.
    if ($value == $test)
    {
        return true;
    }

    return false;
}
avatar Devportobello Devportobello - open - 4 Feb 2015
avatar Devportobello Devportobello - change - 4 Feb 2015
Title
JFormRuleEquals does take into account group
JFormRuleEquals doesn't take into account group
avatar Devportobello Devportobello - change - 4 Feb 2015
The description was changed
avatar Devportobello Devportobello - change - 4 Feb 2015
The description was changed
avatar brianteeman brianteeman - change - 4 Feb 2015
Labels Added: ?
avatar Devportobello Devportobello - change - 18 Mar 2015
Status New Closed
Closed_Date 0000-00-00 00:00:00 2015-03-18 11:31:45
avatar Devportobello Devportobello - close - 18 Mar 2015

Add a Comment

Login with GitHub to post a comment