I have a WebView node in my JavaFX and the page loaded in it has a <input type=file>. I want to set this input's value to a file on disk. I know this is not possible by injecting javascript into the web view. But I'm wondering if I can get access to JavaFX internals in how these input fields are handled and set the value through there. There appears to be no mention of file input controls' handling in the docs so I'm lost on this.
When I click on the file input. JavaFX gives me a native file selector. So, I'm expecting there's some form of handler that is invoked when clicking on a file input, that asks the user to select a file and then fills the file input with this value. That's what I want to do.
I tried just getting the element and setting it's value, but of course, it didn't work.
webEngine.getDocument().getElementById("FileInput")
.setNodeValue("C:\\attachment.pdf");
This piece of code does nothing. No error, no result either.
So, any ideas?
JavaFX internally uses WebKit for the WebView node, thus it have the same security restrictions. It's not possible to set the value of <input type="file"/> programmatically, neither over JavaScript or Java.
I suggest you to use FileChooser without using the WebView node. What the WebView node shows is a select button, which calls a FileChooser, and a label with the selected file name. This can be easily implemented in Java source code using JavaFX.
Related
I am attempting to implement the Daydream keyboard into an app built in Unity and am not able to get this to work. I have added the keyboard prefab as a sibling of the main camera and added two input fields with the onpointerclick function added as instructed. I however get a null reference exception and assume this is due to the daydream keyboard delegate field being blank. The example scene in the SDK shows the daydream delegate example prefab but I am unsure how to implement this for two input fields. Also does the keyboard render in the Unity editor or must it be built and run on a phone?
This is an old question and has probably already been answered, but I figured I'd publicize my answer anyway.
For those reading, if you haven't checked out the Keyboard Demo scene that can be found within the Demos folder of the Google VR Unity package, I would highly recommend doing so. Following this object hierarchy has worked for me in the past.
To answer your first question, it seems that they have included a KeyboardDelegateExample object within the scene's hierarchy, and then used this object as the Keyboard Delegate in the GVRKeyboardManager.
They manage to fake an Input Field by creating a background and overlaying a Text object on top. If this method does not suffice and using an Input Field is crucial in your particular case, then drop your Input Fields into two separate GVRKeyboardCanvas objects.
Clicking on either canvas will activate the GVR Keyboard. You may have to add a small script to manage the transitioning of the input field.
Lastly, no the GVR Keyboard does not render in the Unity Editor, it only appears while running a build. Hopefully this will be addressed in later releases. There are also Keyboard plugins that you may find useful on the Asset Store.
I'm making a JavaFX program for which I would like to use the new Time API. I wanted to use the LocalDatePicker provided in the JFXtras library which would allow users to select multiple localdate objects and would streamline the program's handling of selected objects (as opposed to the similar CalendarPicker in the same library which uses the older date API).
I imported the custom JFXtras controls into JavaFX scene builder, and while the "multiple" selection mode works very well for the JFXtras CalendarPicker control, the same functionality seems broken in the LocalDatePicker control.
Multiple/Range selection does not work in either the preview feature of scene builder, in a compiled FXML/controller file generated in Netbeans, and when simply added to a JavaFX scene, while in all those cases the CalendarPicker control does work. which leads me to believe it is a problem with the control itself and not my implementation. I checked the respective classes in the library and the code handling modeProperty seems identical.
Thing is, the sample program including all controls on the JFXtras page (http://jfxtras.org/resources/java/jfxtras-labs-samples-8.0-r4-SNAPSHOT-shadow.jar) has a multiple selection working for the LocalDatePicker control.
What am I doing wrong?
Sorry if it's an easy fix, I'm pretty new to Java (and JavaFX)
Thanks
Oh yes. This was my fault. Even though there was code to sync the mode value between LocalDatePicker and CalendarPicker, I forgot to set the initial value. In the tests the value is set after the control is visible and then the sync code kicks in. Please try 8.0-r4-SNAPSHOT. Thanks for reporting.
I'm trying to use the QFileDialog widget in PyQT in order to get the name of a file to save results. I'm using the method QFileDialog.getSaveFileName() and, as is expected, if I select an existing file a warning box appears saying that the file exists and offering the possibility to overwrite it. But the problem is that if I select a directory instead of a regular file the same warning box as if it was a normal file appears. I don't like this behavior and I would like a warning box informing there is a directory and it can't be selected, or maybe the OK button disabled until a regular file is selected. Is possible to do? How can I do this, if it is possible?
Thanks
The static functions will open a native dialog, unless you set DontUseNativeDialog with the options parameter, in which case you will get the built-in Qt file-dialog:
path = QFileDialog.getSaveFileName(options=QFileDialog.DontUseNativeDialog)
The built-in dialog is often faster, and generally has more sensible behaviour than the native dialogs. In particular, if you single-click a directory, the Save button changes to an Open button, so a directory can never be selected.
If you absolutely must have an native dialog, you could try setting the DontConfirmOverwrite option. This will allow you to handle any potential overwriting yourself after the dialog has closed.
Functionnaly :
On one of my components of my application, I have an editing/lock system. When a user starts editing, he locks the file so other users cannot edit it.
Problem scenario : When the user activates "edition mode" and leaves screen, I would like to show a alert with two options : save changes, or discard changes.
There are different ways to exit screen :
There is a List on the left side containing other possible editabel data. A click changes the data in my component.
There is a menubar on top leading to other screens.
The edition component is embedded in a Tab navigator. When changing tabs, the alert has to show.
Closing browser.
Do I have to catch all of these events and plug at all those places?
Is there any kind of focusout mecanism?
The answer to the first question is: YES.
You need to watch all possible exit events that could harm the currently edited data.
Well, the problem is now how to manage this properly. Using an MVC framework you would trigger the appropriate commands from your components:
CHANGE_LIST_ITEM (new item)
CHANGE_TAB (new tab)
CHANGE_SCREEN (new screen)
Each command then checks if the currently edited tab has been saved or not. If not, it displays the Alert. Else, if there are no changes, it allows the list, the screen chooser and the tab bar to continue.
So your components (list, screens, tabs) need to implement some kind of rollback or preventDefault mechanism. Generally, changing their state must be allowed by a central validator (in MVC the command).
In the case of the list: I would suggest that the list is not selectable by mouse click but only programmatically. You set a listener on the list item click event. If the command allows setting of a new item it will notify the list. In MVC usually by sending an async message that gets received by the list's mediator. [[And even more correct: The command would set some model properties (e.g. currentListItem) and the model than sends an async message.]]
Edit: For the browser close event, you need to call a JavaScript expert.
I'm developing simple HTML editor and I like to be able to drag and drop from a button that for example represent HTML text line and in the Qwebkit the HTML text line will be created does Qt support such action?
How should I approach such thing?
I believe it does, yes.
What you need to do is set the mime type of your drag event. See here for details. Then on the webkit side, you can read the drops mime type to see what it was.
You can then try one of the following approaches:
Subclassing QWebView to implement dragEnterEvent and dropEvent. You can use event->pos() in the dropEvent to get the position where the drop occured.
Implementing the drop in javascript within your page, eg setting up an event listener for drops or however its done (I've never tried this).