Form and enter..
I have came across old code in the Form and Field implementation and it’s basically implementing form submit when enter is clicked. I was thinking about what would be the right behavior. Therefore I am calling to your opinion here.
Firstly – there are few things form should do:
- it should allow enter-submission by default.
- there should be support for multiple submit buttons and also mechanism to detect which button was pressed
- form should allow non-submit buttons
Here is is one solution:
Form add’s submit button “Ok” always by default. This button is named “default”, and therefore $form->isClicked(‘default’) would acknowledge that Enter was used on the form. atk4_form will be hiding this button by default. With JS it is quite possible that form might already have submit button, such as a floating frame (dialog). However developers shouldn’t rely on isClicked() for this button. If form is submitted externally, isClicked may return false.
Developers should add their own submit buttons if they want them for aesthetics. Form::addDefaultSubmit() will be very similar to addSubmit, but will re-use OK button and will not hide it, and return existing button.
Submits and buttons will use button.html template with tag <button>, although its “type” will be set to either “submit” or “button”. Default button will also attempt to appear highlighted according to the theme.
Visually it will look like regular form have no buttons at all, but if addDefaultButton is used – it will have one button therefore will not break the concept and will work intuitively.
Finally – right now when form is submitted without submit handler defined, it’s tries to JS execute page render and produces AJAX error. Form will provide a fall-back mechanism so if user fails to call js->execute() it will silently ignore submit.
I am also reluctant to finally integrate atk4_form with our default form by default. However you will still be able to disable JS (will be done for login forms as it is more compatible with password-remembering techniques in browsers) through $form->js_widget=null;
Please let me know if I have missed anything.
Changes to the form will be launched on my branch.