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

Form: Prepend Submit Button when submitButton is set #77

Closed
wants to merge 10 commits into from

Conversation

TAINCER
Copy link
Contributor

@TAINCER TAINCER commented Sep 23, 2022

No description provided.

@TAINCER TAINCER requested a review from lippserd September 23, 2022 10:43
@cla-bot cla-bot bot added the cla/signed label Sep 23, 2022
@TAINCER TAINCER changed the title Form prepend Submit Button when submitButton is set Form: Prepend Submit Button when submitButton is set Sep 23, 2022
@nilmerg nilmerg added this to the v0.7.0 milestone Oct 18, 2022
src/Form.php Outdated
return;
}

$attr = clone $this->submitButton->getAttributes();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clone the entire element, since the name must also be the same, or am I mistaken?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't want to clone the whole Submit Element since it doesn't support Deep Cloning, only shallow. I don't know if this would have side effects or Unknown Behavior since I'm changing the Element's styling.

src/Form.php Outdated
}

$attr = clone $this->submitButton->getAttributes();
$attr->setAttribute(Attribute::create('style', 'display: none'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use this style instead:

border: 0;
height: 0;
margin: 0;
padding: 0;
visibility: hidden;
width: 0;

Else, Safari will just ignore the submit button.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these styles, the Element takes up space on top of the Form, resulting in an unwanted Margin. This happens in Chrome and Safari. When using display: none the Element takes up no space. Am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, functionality ;-) The main purpose of such a button is to pick the "correct" submit element when the user presses the Enter/Return key. With display: none behavior depends on the web browser implementation, it might not behave as expected.

Icinga Director does this since v1.0 the following way:

role: none;
tabindex: -1
position: absolute;
left: -100%;

There might be better alternatives, but this seems to do it's job quite well.

src/Form.php Outdated
public function render(): string
{
// Refactor into `ON_ASSEMBLE` once available
$this->prependSubmitButton();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling render more than once also prepends the submit element more than once. This must not happen. Please also add a test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I'd love to see this being implemented for all of our forms, it's IMHO not a good thing to enforce it for every ipl\Html\Form. ipl/html should provide basic building blocks for any kind of HTML, it shouldn't do opinionated magic.

What about providing this method here, giving it a meaningful name (prependedClonedSubmitbutton()?) and not calling it per default? This could then take place in opinionated subclasses, with ipl\web being a good candidate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would I not want to clone the button by default? The form already supports a primary submit button and additional submit elements. I don't see why this should not be supported by default.

@TAINCER TAINCER self-assigned this Oct 25, 2022
@nilmerg nilmerg added the bug Something isn't working label Nov 8, 2022
@TAINCER TAINCER force-pushed the FormSubmitButtonFix branch from 9f50c54 to 35417a6 Compare November 9, 2022 14:49
@TAINCER TAINCER requested a review from lippserd November 9, 2022 14:51
src/Form.php Outdated
Comment on lines 366 to 367
'style',
'border: 0;height: 0;margin: 0;padding: 0;visibility: hidden;width: 0;position: absolute;'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline style is not an option. We can't use that if we want to support Icinga/icingaweb2#4528 in the future.

Though, the only alternative is to provide the first css asset here. That's been a thing for ipl-web only so far, but I see no other solution. A dependency upon Icinga Web or ipl-web here is also not an option. So ipl-html has to provide it by itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do we just give it a class and leave the styling to something else like we do with the decorators?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leave the styling to something else

If that's done by a library like this, without a dependency, I'd be not pleasantly surprised.

It's either an asset here, or .. an idea I had just recently: Make it a trait, put it in ipl-web. (It's mainly an integration "thing", not a HTML or Form "thing") The CSRF trait is also in ipl-web for that reason.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like we do with the decorators

they are optional, which makes it different to this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an idea I had just recently: Make it a trait, put it in ipl-web. (It's mainly an integration "thing", not a HTML or Form "thing") The CSRF trait is also in ipl-web for that reason.

That's what @Thomas-Gelf would also like 😆 Yeah, let's do it like that!

@TAINCER TAINCER closed this Nov 24, 2022
@TAINCER TAINCER deleted the FormSubmitButtonFix branch November 24, 2022 10:29
@nilmerg nilmerg removed this from the v0.7.0 milestone Nov 25, 2022
@nilmerg nilmerg removed the bug Something isn't working label Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants