From 93b4ef64d87e3ad59ff4bbee57fe7f219d0e04ad Mon Sep 17 00:00:00 2001 From: yumoqing Date: Tue, 26 Mar 2024 11:09:15 +0800 Subject: [PATCH] bugfix --- bricks/conform.js | 2 +- bricks/form.js | 5 ++++ bricks/input.js | 61 ++++++++++++++++++++++++++++++++------------ bricks/message.js | 8 +++--- bricks/widget.js | 6 +++++ examples/checkbox.ui | 29 +++++++++++++++++++++ 6 files changed, 90 insertions(+), 21 deletions(-) create mode 100644 examples/checkbox.ui diff --git a/bricks/conform.js b/bricks/conform.js index 8cee484..a087366 100644 --- a/bricks/conform.js +++ b/bricks/conform.js @@ -1,5 +1,5 @@ var bricks = window.bricks || {}; -bricks.Conform = class extends bricks.BMessage { +bricks.Conform = class extends bricks.Message { constructor(opts){ opts.auto_open = true; opts.auto_close = false; diff --git a/bricks/form.js b/bricks/form.js index 348d051..c5fec21 100644 --- a/bricks/form.js +++ b/bricks/form.js @@ -184,6 +184,7 @@ bricks.Form = class extends bricks.VBox { var d = w.getValue(); if (w.required && ( d[name] == '' || d[name] === null)){ bricks.debug('data=', data, 'd=', d); + new bricks.Error({title:'Requirement', message:'required field must input"' + w.label + '"'}) w.focus(); return; } @@ -195,6 +196,10 @@ bricks.Form = class extends bricks.VBox { var running = new bricks.Running({target:this}); try { var data = this.getValue(); + if (! data) { + running.dismiss(); + return; + } this.dispatch('submit', data); if (this.submit_url){ var rc = new bricks.HttpResponse(); diff --git a/bricks/input.js b/bricks/input.js index 8d57b65..5b3deee 100755 --- a/bricks/input.js +++ b/bricks/input.js @@ -11,6 +11,10 @@ bricks.UiType =class extends bricks.Layout { getValue(){ var o = {} o[this.name] = this.resultValue(); + var d = this.getUserData(); + if (d){ + o = bricks.extend(o, d); + } return o; } resultValue(){ @@ -191,13 +195,6 @@ bricks.UiStr =class extends bricks.UiType { this.value = this.dom_element.value; return this.value; } - getValue(){ - this.value = this.dom_element.value; - var k = this.name; - var d = {} - d[this.name] = this.value; - return d; - } setValue(v){ if (! v) v = ''; @@ -357,6 +354,7 @@ bricks.UiCheck =class extends bricks.UiType { }); this.add_widget(this.ms_icon) + this.ms_icon.bind('state_changed', this.set_value_from_input.bind(this)); } @@ -369,6 +367,10 @@ bricks.UiCheck =class extends bricks.UiType { this.value = v; var o = {}; o[this.name] = this.value; + var d = this.getUserData(); + if (d){ + o = bricks.extend(o, d); + } this.dispatch('changed', o); } setValue(v){ @@ -433,13 +435,28 @@ bricks.UiCheckBox =class extends bricks.UiType { build_checkboxs(){ var data = this.data; this.input_boxs = []; + if (this.multicheck){ + if (typeof this.value != typeof []){ + this.value = [this.value]; + } + } + for (var i=0; i= 0){ + opts.value = true; + } } + else { + if (this.value == value){ + opts.value = true + } + } + opts.name = value; var check = new bricks.UiCheck(opts); var otext = data[i][this.textField]; var txt = new bricks.Text({ @@ -464,11 +481,22 @@ bricks.UiCheckBox =class extends bricks.UiType { } set_value_from_input(event){ event.stopPropagation(); - var e = event.target; - if (e.state=='checked'){ - this.value.push(e.value); + var e = event.target.bricks_widget; + if (this.multicheck){ + if (e.value){ + this.value.push(e.name); + } else { + this.value.remove(e.name) + } } else { - this.value.remove(e.value) + for (var i=0;i