This commit is contained in:
yumoqing 2024-03-26 11:09:15 +08:00
parent d6880c3081
commit 93b4ef64d8
6 changed files with 90 additions and 21 deletions

View File

@ -1,5 +1,5 @@
var bricks = window.bricks || {}; var bricks = window.bricks || {};
bricks.Conform = class extends bricks.BMessage { bricks.Conform = class extends bricks.Message {
constructor(opts){ constructor(opts){
opts.auto_open = true; opts.auto_open = true;
opts.auto_close = false; opts.auto_close = false;

View File

@ -184,6 +184,7 @@ bricks.Form = class extends bricks.VBox {
var d = w.getValue(); var d = w.getValue();
if (w.required && ( d[name] == '' || d[name] === null)){ if (w.required && ( d[name] == '' || d[name] === null)){
bricks.debug('data=', data, 'd=', d); bricks.debug('data=', data, 'd=', d);
new bricks.Error({title:'Requirement', message:'required field must input"' + w.label + '"'})
w.focus(); w.focus();
return; return;
} }
@ -195,6 +196,10 @@ bricks.Form = class extends bricks.VBox {
var running = new bricks.Running({target:this}); var running = new bricks.Running({target:this});
try { try {
var data = this.getValue(); var data = this.getValue();
if (! data) {
running.dismiss();
return;
}
this.dispatch('submit', data); this.dispatch('submit', data);
if (this.submit_url){ if (this.submit_url){
var rc = new bricks.HttpResponse(); var rc = new bricks.HttpResponse();

View File

@ -11,6 +11,10 @@ bricks.UiType =class extends bricks.Layout {
getValue(){ getValue(){
var o = {} var o = {}
o[this.name] = this.resultValue(); o[this.name] = this.resultValue();
var d = this.getUserData();
if (d){
o = bricks.extend(o, d);
}
return o; return o;
} }
resultValue(){ resultValue(){
@ -191,13 +195,6 @@ bricks.UiStr =class extends bricks.UiType {
this.value = this.dom_element.value; this.value = this.dom_element.value;
return this.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){ setValue(v){
if (! v) if (! v)
v = ''; v = '';
@ -357,6 +354,7 @@ bricks.UiCheck =class extends bricks.UiType {
}); });
this.add_widget(this.ms_icon) this.add_widget(this.ms_icon)
this.ms_icon.bind('state_changed', this.set_value_from_input.bind(this)); 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; this.value = v;
var o = {}; var o = {};
o[this.name] = this.value; o[this.name] = this.value;
var d = this.getUserData();
if (d){
o = bricks.extend(o, d);
}
this.dispatch('changed', o); this.dispatch('changed', o);
} }
setValue(v){ setValue(v){
@ -433,13 +435,28 @@ bricks.UiCheckBox =class extends bricks.UiType {
build_checkboxs(){ build_checkboxs(){
var data = this.data; var data = this.data;
this.input_boxs = []; this.input_boxs = [];
if (this.multicheck){
if (typeof this.value != typeof []){
this.value = [this.value];
}
}
for (var i=0; i<data.length;i++){ for (var i=0; i<data.length;i++){
var hbox = new bricks.HBox({height:"auto",width:"100%"}); var hbox = new bricks.HBox({height:"auto",width:"100%"});
var opts = {} var opts = {}
var value = data[i][this.valueField]; var value = data[i][this.valueField];
if (this.value == value){ opts.value = false;
opts.value = true; if (this.multicheck){
if (this.value.indexOf(value) >= 0){
opts.value = true;
}
} }
else {
if (this.value == value){
opts.value = true
}
}
opts.name = value;
var check = new bricks.UiCheck(opts); var check = new bricks.UiCheck(opts);
var otext = data[i][this.textField]; var otext = data[i][this.textField];
var txt = new bricks.Text({ var txt = new bricks.Text({
@ -464,11 +481,22 @@ bricks.UiCheckBox =class extends bricks.UiType {
} }
set_value_from_input(event){ set_value_from_input(event){
event.stopPropagation(); event.stopPropagation();
var e = event.target; var e = event.target.bricks_widget;
if (e.state=='checked'){ if (this.multicheck){
this.value.push(e.value); if (e.value){
this.value.push(e.name);
} else {
this.value.remove(e.name)
}
} else { } else {
this.value.remove(e.value) for (var i=0;i<this.input_boxs.length;i++){
var e1 = this.input_boxs[i];
if (e1 != e){
e1.setValue(false);
}
}
this.value = e.name;
console.log('this is singlecheck ....', this.value);
} }
var o = {}; var o = {};
o[this.name] = this.value; o[this.name] = this.value;
@ -478,13 +506,14 @@ bricks.UiCheckBox =class extends bricks.UiType {
return this.value; return this.value;
} }
setValue(v){ setValue(v){
var thisvalue = this.value;
if (Array.isArray(v)){ if (Array.isArray(v)){
this.value = v; thisvalue = v;
} else { } else {
this.value = [v]; thisvalue = [v];
} }
for (var i=0; i<this.input_boxs.length; i++){ for (var i=0; i<this.input_boxs.length; i++){
if (this.value.includes(this.data[i][this.valueField])){ if (thisvalue.includes(this.data[i][this.valueField])){
this.input_boxs[i].setValue(true); this.input_boxs[i].setValue(true);
} else { } else {
this.input_boxs[i].setValue(false); this.input_boxs[i].setValue(false);

View File

@ -59,7 +59,7 @@ bricks.BPopup = class extends bricks.VBox {
} }
} }
bricks.BMessage = class extends bricks.Modal { bricks.Message = class extends bricks.Modal {
/* /*
{ {
title: title:
@ -90,7 +90,7 @@ bricks.BMessage = class extends bricks.Modal {
} }
} }
bricks.BError = class extends bricks.BMessage { bricks.Error = class extends bricks.Message {
constructor(opts){ constructor(opts){
super(opts); super(opts);
this.panel.set_css('error'); this.panel.set_css('error');
@ -115,6 +115,6 @@ bricks.PopupForm = class extends bricks.BPopup {
this.dismiss(); this.dismiss();
} }
} }
bricks.Factory.register('Message', bricks.BMessage); bricks.Factory.register('Message', bricks.Message);
bricks.Factory.register('Error', bricks.BError); bricks.Factory.register('Error', bricks.Error);
bricks.Factory.register('PopupForm', bricks.PopupForm); bricks.Factory.register('PopupForm', bricks.PopupForm);

View File

@ -28,6 +28,12 @@ bricks.JsWidget = class {
this.bind('mouseout', w.hide.bind(w)); this.bind('mouseout', w.hide.bind(w));
} }
} }
getUserData(){
return this.user_data || null;
}
setUserData(v){
this.user_data = v;
}
create(){ create(){
this.dom_element = this._create('div') this.dom_element = this._create('div')
} }

29
examples/checkbox.ui Normal file
View File

@ -0,0 +1,29 @@
{
"widgettype":"UiCheckBox",
"options":{
"name":"cb",
"multicheck":false,
"uitype":"checkbox",
"valueField":"value",
"textField":"text",
"data":[
{
"value":"test1",
"text":"Test1"
},
{
"value":"test2",
"text":"Test 2"
}
]
},
"binds":[
{
"wid":"self",
"event":"changed",
"actiontype":"script",
"target":"self",
"script":"alert(JSON.stringify(event.params))"
}
]
}