Closed G-Mein closed 4 years ago
Hi Mark how are you? :wave:
Hmm, I'm not sure what you have in mind with the ClientEvent or SystemEvent
- do you perhaps mean the userOriginated
flag? If not, could you describe those two things in more detail please?
I'm fine, thanks for asking :) hope you all are fine too. In detail, I created a custom component with the help of Jürgen Treml to create a signing pad in vaadin. this is basicly a canvas that creates an SVG file. I added a changeEventListener like this:
this.signatureField.addValueChangeListener(changeEvent -> {
if (changeEvent.isFromClient()) {
this.submitButton.setEnabled(true);
}
});
because, initially the canvas value is "" When you initialize the JS on it, it's filled with white so it's not "" anymore. This had to be catched up so i decided to make the if clause with " if (changeEvent.isFromClient()) {" to only get the changeEvent, when the user is really clicking and signing on the pad itselfs.
Now my testing is like this:
assertFalse(MyView.submitButton.isEnabled());
_setValue(MyView.signatureField, "test");
assertTrue(MyView.submitButton.isEnabled());
last one is not true. The setValue triggers the changeEvent, but it's a systemEvent. I thought that you told us in the training, that the events with _ prefix are as they would be done in the browser.
Hope you can follow my thinking and using.
I used to use _setValue, because I had no idea how to simulate a pressed mouse on the canvas :D
Thank you for a thorough explanation. You're right - it's good to always use _setValue()
instead of setValue()
since _setValue()
also checks whether the component is enabled.
Unfortunately, _setValue()
has no other choice but to call setValue()
which will always fire the listener as if coming from the server (isFromClient()
will return false).
However, in your case you can simply use _fireValueChange(MyView.signatureField, true)
instead. I will mention this possibility in _setValue()
's javadoc.
Thank you very much. I will test that and give feedback.
it works like a charm, thank you very much!
Awesome, thank you for letting me know! I've also added the javadoc to the _setValue()
function :+1:
I created a signing pad where I have a changeEventListener on to check, if a signing was given. Then a button will be enabled. I had to check, if the valuechange is a ClientEvent or SystemEvent. Sadly the _setValue from karibu does a SystemEvent so I can't check the flow in my app.
Is there a way to set events as ClientEvent in Karibu?
Vaadin Version: 14.3.2 Karibu version: 1.1.26
btw, I'm Mark from germany, we had some training with you few weeks ago ;)