addCondition – own validation

Notice: This thread is very old.
Roman Kubica
Member | 2


I have this form. If I use check box then toggle works. If I use my condition, nothing happens. I have also try to add third parameter as TRUE, but same result: no toggling. There is no error in debug mode.

Would anyone be able to help me please what am I doing wrong? Am I passing parameter country incorrectly? I used this tutorial "":…cni-pravidla

$form->addSelect('country', 'Country:')
    ->setPrompt('Choose nationality')
    ->setItems($this->countries, FALSE)

    ->addCondition($form::EQUAL, TRUE)
class TaxFormRules

    const COUNTRY = 'App\Model\TaxFormRules::validateCountry';

    public static function validateCountry(IControl $control, $country)
        // validace, zda se jedné o e-mail z domény $domain
        if (substr($country, 0, 1) == "A") {
            return true;
        }else {
            return false;
$this->countries = array(
            'AF' => 'Afghanistan',
            'AL' => 'Albania',
            'DZ' => 'Algeria',
            'YE' => 'Yemen',
            'ZM' => 'Zambia',
            'ZW' => 'Zimbabwe',
            'AX' => 'Åland Islands',
David Matějka
Moderator | 6427

To make toggle working, you have to write client-side validation in js:

Nette.validators.AppModelTaxFormRules_validateCountry = function (control) {

btw, remove $form['country']->value in the addCondition. it cannot work.