SVGHMI: Keypad is now keeping Javascript type constency. In other words, if a number was given as initial value, input value will have to convert to number in order to be valid. In case invalid value is entered, initial value is restored.
--- a/svghmi/widget_keypad.ysl2 Thu Aug 20 14:12:49 2020 +0200
+++ b/svghmi/widget_keypad.ysl2 Fri Aug 21 13:22:54 2020 +0200
@@ -88,9 +88,15 @@
}
on_Enter_click() {
- end_modal.call(this);
- let callback_obj = this.result_callback_obj;
- callback_obj.edit_callback(this.editstr);
+ let coercedval = (typeof this.initial) == "number" ? Number(this.editstr) : this.editstr;
+ if(isNaN(coercedval)){
+ this.editstr = String(this.initial);
+ this.update();
+ } else { // revert to initial so it explicitely shows input was ignored
+ let callback_obj = this.result_callback_obj;
+ end_modal.call(this);
+ callback_obj.edit_callback(coercedval);
+ }
}
on_BackSpace_click() {
@@ -137,11 +143,13 @@
result_callback_obj = undefined;
start_edit(info, valuetype, callback_obj, initial,size) {
show_modal.call(this,size);
- this.editstr = initial;
+ this.editstr = String(initial);
this.result_callback_obj = callback_obj;
this.Info_elt.textContent = info;
this.shift = false;
this.caps = false;
+ this.initial = initial;
+
this.update();
}