Bug: global editor.validator($afterFields, function(...)) does not work when called with 'false'

Bug: global editor.validator($afterFields, function(...)) does not work when called with 'false'

wireddunswiredduns Posts: 9Questions: 1Answers: 0

Relates to Editor 2.4.3

2 problems:

1 - There seems to be no default value false (as mentioned in the doc) for $afterFields

public function validator($afterFields, $_ = null)

should it not be:

public function validator($afterFields = false, $_ = null)

2 - when $afterFields is set to false (evaluate before fields), $_ is set to false with the following line:

        // Argument shift
        $_ = $afterFields;

which in turn makes the function always return false, rather than $this (see _getSet in Ext.php)

Workaround:
remove the lines:

// Argument shift
$_ = $afterFields;

and the validator works.

Regards
Mark

Replies

  • wireddunswiredduns Posts: 9Questions: 1Answers: 0

    Like this also works, and does not involve setting the default of $afterFields, which is taken care of by the Argument shift in case it is a callable:

        public function validator($afterFields, $_ = null)
        {
            if (is_bool($afterFields)) {
                if ($afterFields === true) {
                    return $this->_getSet($this->_validatorAfterFields, $_, true);
                } else {
                    return $this->_getSet($this->_validator, $_, true);
                }
            }
    
            // Argument shift
            $_ = $afterFields;
    
            return $this->_getSet($this->_validator, $_, true);
        }
    
  • allanallan Posts: 64,829Questions: 1Answers: 10,731 Site admin

    Hi Mark,

    Thanks for the feedback on this.

    1) should it not be: [...]

    I don't think it should - the idea is that Editor->validator() should effectively allow an overload:

    $editor->validator( $fn );
    $editor->validator( true, $fn );
    $editor->validator( false, $fn );
    

    2) which in turn makes the function always return false

    Good point! It doesn't correctly handle false being passed in as the first argument. I normally try to do any argument shifting at the top of the function to avoid tying myself in knots, and for whatever reason I didn't there. I've reworked it now to address this.

    Thanks again!

    Allan

  • wireddunswiredduns Posts: 9Questions: 1Answers: 0

    Great

    Thanks
    Mark

Sign In or Register to comment.