Skip to content

Forms: Undefined property #139

@Pub4Game

Description

@Pub4Game

Hello!

I need to create a form with a field read-only and later make it active, but get the error after submit - Undefined property: Nette\Utils\ArrayHash::$test2. Below I have given examples of code that I use. Form becomes active and you can select any item after $this->redrawControl('forms').

Example form:

public function create()
{
	$form = new Form();

	$form->addSelect('test', '', [
		'1' => 'lalala'
	])
		->setRequired('Just do it!');

	$form->addSelect('test2', '', [
		'1' => '123123'
	])
		->setDisabled(true)
		->setRequired('Just do it!');

	$form->addProtection('');

	$form->addSubmit('send', 'create');

	$form->onSuccess[] = function (Form $form, $values) {
		$form->addError($values->test2);
	};

	return $form;
}

I have a script that tracks changes test

public function handleChange($change)
{
	if ($change) {
		$this['orderForm']['test2']->setDisabled(false);
	} else {
		$this['orderForm']['test2']->setDisabled(true);
	}
	$this->redrawControl('wrapper');
	$this->redrawControl('forms');
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions