nette / forms

📝 Generating, validating and processing secure forms in PHP. Handy API, fully customizable, server & client side validation and mature design.
https://doc.nette.org/forms
Other
497 stars 147 forks source link

netteForms.js doesn't toggle properly when form is reset #306

Closed jdvorak23 closed 1 year ago

jdvorak23 commented 1 year ago

Version: netteForms.js 3.3.0

Bug Description

Toggle in netteForms.js doesn't work properly, whent there is a type='reset' button, or the form is reset() anyhow. 'reset' event doesn't fire 'change' event on controls, but changes them. If you check Checkbox in example, TextArea will show, if you then click reset button, Checkbox is unchecked by reset, but TextArea is not toggled properly.

Steps To Reproduce

class TestFormFactory
{
    public function create() : Form
    {
        $form = new Form();
        $form->addEmail('email', 'Your email');
        $form->addCheckbox('send_me')
            ->addCondition($form::Equal, true)
            ->toggle('#frm-testForm-address');
        $form->addTextArea('address');
        $form->addSubmit("save", "Save");
        $form->addButton('cancel', 'Cancel')
            ->setHtmlAttribute("type", "reset");
        return $form;
    }
}

Expected Behavior

Form's 'reset' event should be handled for toggling properly.

Possible Solution

Somehow handle 'reset' event on forms and toggle controls which needs it.