Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forms: Undefined property #139

Closed
Pub4Game opened this issue Dec 21, 2016 · 8 comments
Closed

Forms: Undefined property #139

Pub4Game opened this issue Dec 21, 2016 · 8 comments

Comments

@Pub4Game
Copy link

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');
}
@dg
Copy link
Member

dg commented Dec 21, 2016

Please for personal support please use forum at https://forum.nette.org or gitter https://gitter.im/nette/nette

You didn't read nette/security#19?

@dg dg closed this as completed Dec 21, 2016
@Pub4Game
Copy link
Author

There's no question. There is a problem. After I use the setDisabled() out of the field it is impossible to get information even if it is active

@dg
Copy link
Member

dg commented Dec 22, 2016

Ok, sorry.

Can you try to replace setDisabled in BaseControl to this?

	/**
	 * Disables or enables control.
	 * @param  bool
	 * @return static
	 */
	public function setDisabled($value = TRUE)
	{
		if ($this->disabled = (bool) $value) {
			$this->setValue(NULL);
		} elseif (($form = $this->getForm(FALSE)) && $form->isAnchored() && $form->isSubmitted()) {
			$this->loadHttpData();
		}
		return $this;
	}

@Pub4Game
Copy link
Author

Unfortunately, this did not help me. I still get this error

Undefined property: Nette\Utils\ArrayHash::$test2

@dg
Copy link
Member

dg commented Dec 22, 2016

You must call setDisabled(FALSE) after form is submitted, not in AJAX request before.

@Pub4Game
Copy link
Author

lol.
I want to make a field available after selecting item in a test.
Therefore, the user first selects the item in test, then I use $this['orderForm']['test2']->setDisabled(false)->setItems($rate);

How do I call setDisabled(false) after form is submitted? xD

@dg
Copy link
Member

dg commented Dec 22, 2016

You should somehow save information that field is not disabled. In hidden field or etc. You can discuss it on forum ;)

@Pub4Game
Copy link
Author

Okay) Thank you for such quick support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants