# HG changeset patch # User Edouard Tisserant # Date 1598008974 -7200 # Node ID 52f6548982d4730d7d58881ae3ed58098c3b1593 # Parent 2f6dfb99d09488994bc5e9a95b4dd1ec05f6ee93 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. diff -r 2f6dfb99d094 -r 52f6548982d4 svghmi/widget_keypad.ysl2 --- 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(); }