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

@Pub4Game Pub4Game commented Dec 21, 2016

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

This comment has been minimized.

Copy link
Member

@dg 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 Dec 21, 2016
@Pub4Game

This comment has been minimized.

Copy link
Author

@Pub4Game Pub4Game commented Dec 21, 2016

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

This comment has been minimized.

Copy link
Member

@dg 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

This comment has been minimized.

Copy link
Author

@Pub4Game Pub4Game commented Dec 22, 2016

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

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

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Dec 22, 2016

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

@Pub4Game

This comment has been minimized.

Copy link
Author

@Pub4Game Pub4Game commented Dec 22, 2016

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

This comment has been minimized.

Copy link
Member

@dg 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

This comment has been minimized.

Copy link
Author

@Pub4Game Pub4Game commented Dec 22, 2016

Okay) Thank you for such quick support!

dg added a commit that referenced this issue Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.