Low-Level Fields rules and conditions

alnux
Member | 139
+
0
-

Hello, I would like to know how to add validations and rules to low-level fields.
for example requesting that a field is required (rules) or adding conditions
on documentations only show how to sanitize them

i will apreciate your help

David Grudl
Nette Core | 8228
+
0
-

You can't.

dakur
Member | 493
+
+1
-

You can't do it for fields, but you can do it for the form if at least submit button is forms-generated.

$form = new Form();
$form->addSubmit('submit');
$form->onSuccess[] = function () {
	$data = $form->getHttpData($form::DataText, 'sel[]');
	if (...) { // validation
		$form->addError('...');
		return;
	}

	// handle if ok
};

Last edited by dakur (2023-10-02 10:18)