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

Strict types & hidden field #152

Closed
lukascellar opened this issue Apr 19, 2017 · 2 comments
Closed

Strict types & hidden field #152

lukascellar opened this issue Apr 19, 2017 · 2 comments
Milestone

Comments

@lukascellar
Copy link

@lukascellar lukascellar commented Apr 19, 2017

  • bug report? no
  • feature request? yes
  • version: 3.0.0

Description

Currently value of hidden field is always casted to string, even if value is null. I would like to propose to allow null value or cast value to integer/float etc if there are defined validation rules.

forms/src/Forms/Controls/HiddenField.php:

public function setValue($value)
{
	if (!is_scalar($value) && $value !== NULL && !method_exists($value, '__toString')) {
		throw new Nette\InvalidArgumentException(sprintf("Value must be scalar or NULL, %s given in field '%s'.", gettype($value), $this->name));
	}
	if (!$this->persistValue) {
		$this->value = (string) $value;
	}
	return $this;
}
@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Apr 23, 2017

What about addRule(Form::INTEGER) on hidden field?

@lukascellar

This comment has been minimized.

Copy link
Author

@lukascellar lukascellar commented Apr 23, 2017

Works addRule(Form::INTEGER) with hidden input in 2.4? Tried it now, but in onSuccess callback value of id is still a string.

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.