Closed adriatic closed 8 years ago
Right so Telerik's API sample uses MVVM framework stuff of Kendo. We need to translate stuff like kendo.observable into Aurelia which isn't a straight forward thing to do.
What I would do is create @bindable
variables for all properties (background, bordercolor, border width etc) and bind each control to these properties. For example with the background color:
<input id="backgroundColor" k-color-picker="k-value.two-way: background."/>
Because every property is @bindable, you can create a change handler for each of these properties:
@bindable background = '#FFFFFF';
backgroundChanged() {
// update the qrcode
}
Note the <propname>Changed
convention. But you'll notice that it would be quite a lot of code to create a change handler for every property, so I recommend using the global propertyChanged handler instead:
@bindable background = '#FFFFFF';
propertyChanged(prop, newValue, oldValue) {
// where prop = background if the background property has changed
}
In the propertyChanged function you need to refresh the qrcode. You do this by passing all these properties to setOptions
:
propertyChanged(prop, newValue, oldValue) {
this.qrcode.setOptions({
background: this.background
});
}
because you use the change event handlers of the @bindable decorator, you won't need some of the k-on-change
event handlers anymore
The code
propertyChanged(prop, newValue, oldValue) {
this.qrcode.setOptions({
background: this.background
});
}
seems wrong - it does not use any of its parameters and has a very specific code (that handles onlu background property)
I would think that the method's code should have a switch
statement (assuming that JavaScript has that statement) on prop
and then set each option based on prop value. As I know that you know that, I will assume that you just write a "symbol" for real propertyChanged method :-)
Yes, but you don't have to use those parameters at all:
propertyChanged() {
this.qrcode.setOptions({
background: this.background
});
}
The propertyChanged is our signal that something has changed and that we have to redraw the QR code. I only added the background property to demonstrate how it would work
Note that instead of the initial value object you used:
viewModel = {
qrValue: "Hello World",
qrOptions: {
errorCorrection: "L",
encoding: "ISO_8859_1",
background: "#FFFFFF",
color: "#000000",
size: 200,
border: {
color: "#FFFFFF",
width: 0
}
}
};
you can now put the initial values per @bindable
property: @bindable background = '#FFFFFF'
After all this jostling :-) - checked in an incomplete QR code into 0.6.0 branch, simply to get this process going.
There are three open issues:
Also note that I (by copying the Barcode wrapper) got stuck with that validValue
think which I can see the purpose off (show the KendoUI error) but obviously do not know how to use in the context of this sample
_I would like to use this text (with your answers) as a part of the online help for app developers_
Issue 1
How to get the QR Code rendered initially A simple way to do that is to use the "literal bind" like this
However, the original example uses this JavaScript "structure" to define the initial values of all settings for all components on this page - not just the QR Code
constructor
in the JavaScript that would invoke thesetOptions
method that would redraw the widgetIssue 2
Can you please "transcribe" the jQuery code from the original sample into ES6 code by correcting this attempt I wrote
Here is my HTML which I believe is fine (with the exception that I did not pepper each UI element with "event handler" as I do not want to for example redraw the whole widget after each click on the
numeric text box