forms icon indicating copy to clipboard operation
forms copied to clipboard

Helper for closures and non-static methods

Open 2bad2furious opened this issue 7 years ago • 7 comments

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

Description

I think it would be great to have helpers for closures and non-static methods. It can make JS validation easier and could lead to better code-writing. Correct me if I'm wrong, but for a good JS validation you have to use static methods or named functions that honestly don't belong there.

Naming those methods and closures could look like:

  • Non-static methods' names could replace named functions (Class->methodname would result in {"op":"methodname",...})
  • Non-static methods' names could look similar to current static methods' names (Class->methodname would result in {"op":"Class[some separator]methodname"})
  • Closures' names could be generated by the name attribute as seen in my example below
  • Users could name methods and closures themselves

exportRules() EXAMPLE

public static function exportRules(Rules $rules) { $payload = []; foreach ($rules as $rule_key => $rule) { if (!is_string($op = $rule->validator)) { $callback_name = Nette\Utils\Callback::toString($op); if ($callback_name === "{closure}") { $op = $rule->control->getName() . "_rule" . $rule_key; } else if (Nette\Utils\Callback::isStatic($op)) { $op = $callback_name; } else { //TODO replace for better separator instead of :: (requires js changes as well :/ $op = $callback_name; } /* * Original code that started on line 100 after 'if(!is_string...' * * if (!Nette\Utils\Callback::isStatic($op)) { continue; } $op = Nette\Utils\Callback::toString($op);*/ } //method continues as it should

2bad2furious avatar Aug 05 '17 08:08 2bad2furious

Please use only english on GitHub.

dg avatar Aug 05 '17 09:08 dg

Rewriten in English.

2bad2furious avatar Aug 05 '17 09:08 2bad2furious

Thanks

dg avatar Aug 05 '17 10:08 dg

Non-static methods' names could look similar to current static methods' names (Class->methodname would result in {"op":"Class[some separator]methodname"})

👍

Closures' names could be generated by the name attribute as seen in my example below

👎 it is too tricky

Users could name methods and closures themselves

That would be fine, but there is no way to do it.

dg avatar Aug 20 '17 15:08 dg

You could achieve that by doing something like $form->....->addRule(callable,"name"); I don't think anything would change for other types of functions.

2bad2furious avatar Aug 20 '17 18:08 2bad2furious

How is this related with onSuccess?

dg avatar Aug 20 '17 18:08 dg

Brainlag, sry.

2bad2furious avatar Aug 20 '17 18:08 2bad2furious