bugfix
This commit is contained in:
parent
d6880c3081
commit
93b4ef64d8
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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<data.length;i++){
|
||||
var hbox = new bricks.HBox({height:"auto",width:"100%"});
|
||||
var opts = {}
|
||||
var value = data[i][this.valueField];
|
||||
if (this.value == value){
|
||||
opts.value = false;
|
||||
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 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.value)
|
||||
this.value.remove(e.name)
|
||||
}
|
||||
} else {
|
||||
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 = {};
|
||||
o[this.name] = this.value;
|
||||
@ -478,13 +506,14 @@ bricks.UiCheckBox =class extends bricks.UiType {
|
||||
return this.value;
|
||||
}
|
||||
setValue(v){
|
||||
var thisvalue = this.value;
|
||||
if (Array.isArray(v)){
|
||||
this.value = v;
|
||||
thisvalue = v;
|
||||
} else {
|
||||
this.value = [v];
|
||||
thisvalue = [v];
|
||||
}
|
||||
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);
|
||||
} else {
|
||||
this.input_boxs[i].setValue(false);
|
||||
|
@ -59,7 +59,7 @@ bricks.BPopup = class extends bricks.VBox {
|
||||
}
|
||||
}
|
||||
|
||||
bricks.BMessage = class extends bricks.Modal {
|
||||
bricks.Message = class extends bricks.Modal {
|
||||
/*
|
||||
{
|
||||
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){
|
||||
super(opts);
|
||||
this.panel.set_css('error');
|
||||
@ -115,6 +115,6 @@ bricks.PopupForm = class extends bricks.BPopup {
|
||||
this.dismiss();
|
||||
}
|
||||
}
|
||||
bricks.Factory.register('Message', bricks.BMessage);
|
||||
bricks.Factory.register('Error', bricks.BError);
|
||||
bricks.Factory.register('Message', bricks.Message);
|
||||
bricks.Factory.register('Error', bricks.Error);
|
||||
bricks.Factory.register('PopupForm', bricks.PopupForm);
|
||||
|
@ -28,6 +28,12 @@ bricks.JsWidget = class {
|
||||
this.bind('mouseout', w.hide.bind(w));
|
||||
}
|
||||
}
|
||||
getUserData(){
|
||||
return this.user_data || null;
|
||||
}
|
||||
setUserData(v){
|
||||
this.user_data = v;
|
||||
}
|
||||
create(){
|
||||
this.dom_element = this._create('div')
|
||||
}
|
||||
|
29
examples/checkbox.ui
Normal file
29
examples/checkbox.ui
Normal 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))"
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user