I’m trying to add some custom javascript to a screen to improve the usability and visual appearance, but I’m stuck on one (probably) minor issue: The javascript component takes up halve of the screen size, although it hasn’t any visual representation.
MyJsComponent jsComponent = new MyJsComponent();
jsComponent.setHeight("0");
getWindow().unwrap(Layout.class).addComponent(jsComponent);
MyJsComponent is a com.vaadin.ui.AbstractJavaScriptComponent. Everything else works as expected, but I can’t somehow “hide” the component from the view.
If I do a jsComponent.setVisible(false); then the component won’t load at all.
By default, containers without the expand attribute provide equal space for all nested components, that why your component takes half of the screen size. For more details, take a look at the Layout Rules section in the docs.
Could you please describe in more details what is your component purpose, so I can suggest how to add it to a screen without taking a place on a screen layout?
@gorelov Hi Gleb, thanks for you reply. I want to add some custom JavaScript to a page (it’s called classic UI I think - vaadin…) so I can fix some layout and usability problems with the forms. I use the responsive addon, but it has some issues. To fix those, I set the width of some components manually with JS. I found no other way to add custom JS, than to implement the com.vaadin.ui.AbstractJavaScriptComponent and add it to the layout, but when I do this, it takes up halve the space of the screen, although it doesn’t have any visual representation.
I hope I could make a bit clearer and thanks for the effort.
There you see two problems:
(1) the one I mentioned in this thread, under Application->Test Entities->Create. I added many “lorem ipsum” labels, so you can easily see, that there is an “empty” component underneath the form.
(2) If you set the width of the textField components to 100%, they actually get a surrounding element, that has 0px set to width.
Thank you for the demo project. As I mentioned above, you don’t need a UI component in order to execute some JavaScript code. In your case, you can replace your component with the following:
@gorelov Thanks, that’s awesome - I didn’t know I can insert JavaScript that way. Is that somewhere in the documentation also, so I can maybe get more information on that?
Thanks a lot for your hint with the layout, that’s way better and cleaner of course.
I see the issue you linked is open for over a year now, is this addon maintained or is its use not recommended?
@gorelov Good to hear it’s maintained. Thanks for the hint with the Vaadin documentation. Where can I vote, I can’t find the issue on YouTrack and on GitHub I can only subscribe to the issue, what I already did.