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

addCondition - EQUAL #102

Closed
aleswita opened this issue Jan 4, 2016 · 2 comments
Closed

addCondition - EQUAL #102

aleswita opened this issue Jan 4, 2016 · 2 comments

Comments

@aleswita
Copy link
Contributor

@aleswita aleswita commented Jan 4, 2016

Hi,

na nize uvedene ukazce mi spatne funguje vnorena podminka EQUAL, jakmile porovnavaci hodnota je prazdne pole bez hodnot (toogle "from" je stale skryt). Jakmile odstranim podminku (EQUAL podminka neni vnorena):

->addConditionOn($form["namespace"], Forms\Form::EQUAL, 1)

tak vse funguje spravne.
Situaci momentalne resim zpusobem, ze misto prazdneho pole [] vracim pole s jednou hodnotou [-1]

$form->addSelect("namespace", "Namespace")
    ->setItems($this->model->getNamespacesArray())
    ->setPrompt("---");

$form->addSelect("reason", "Reason")
    ->setItems($this->model->getReasonsArray())
    ->addConditionOn($form["namespace"], Forms\Form::EQUAL, 1)
        ->toggle("reason-label")
        ->toggle("reason-input")
        ->addCondition(~Forms\Form::EQUAL,  $this->model->getNoNeedFrom()) // []
            ->toggle("from")
        ->endCondition()
        ->addCondition(~Forms\Form::EQUAL, $this->model->getNoNeedTo()) // [2, 5, 6]
            ->toggle("to")
        ->endCondition()
    ->endCondition();

netteForms.js mam aktualni verzi.

@dg

This comment has been minimized.

Copy link
Member

@dg dg commented Jan 13, 2016

>addCondition(~Forms\Form::EQUAL, []) should be always evaluated as false. Isn't it?

@aleswita

This comment has been minimized.

Copy link
Contributor Author

@aleswita aleswita commented Jan 15, 2016

Hi David,

yes is it...

Look the full example below for test and see my code comment

    protected function createComponentForm()
    {
        $form = new Nette\Application\UI\Form;

        $form->addSelect("namespace", "Namespace:", [1 => "first", 2 => "second"])
            ->setPrompt("---");

        $form->addSelect("reason", "Reason:", [1 => 1, 2 => 2, 3 => 3, 4 => 4])
            ->setPrompt("---");

        $form->addText("from", "From:");

        $form->addText("to", "To:");

        $form["reason"]
            ->addConditionOn($form["namespace"], Form::EQUAL, 1)
                ->addCondition(~Form::EQUAL, [3, 4])
                    ->toggle("from")
                ->endCondition()
            ->endCondition()
            ->addConditionOn($form["namespace"], Form::EQUAL, 2)// if I will remove this condition, below condition functionality are ok
                ->addCondition(~Form::EQUAL, [])// if array empty, condition still false... if array have some value, functionallity are ok
                    ->toggle("to")
                ->endCondition()
            ->endCondition();

        return $form;
    }
{layout none}
<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <script src="{$basePath}/js/netteForms.js"></script>
 </head>
 <body>
  {form form}
   <div id="namespace">
    {label namespace /} {input namespace}
   </div>
   <hr>
   <div id="reason">
    {label reason /} {input reason}
   </div>
   <hr>
   <div id="from">
    {label from /} {input from}
   </div>
   <hr>
   <div id="to">
    {label to /} {input to}
   </div>
  {/form}
 </body>
</html>
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.