This commit is contained in:
yumoqing 2024-02-21 18:42:07 +08:00
parent 397f13e2b9
commit e8451e5f1f

View File

@ -22,22 +22,6 @@ bricks.FormBody = class extends bricks.VBox {
opts.scrollY = 'scroll';
super(opts);
this.name_inputs = {};
/*
if (this.opts.title){
var t = new bricks.Title2({
otext:this.opts.title,
height:'auto',
i18n:true});
this.add_widget(t);
}
if (this.opts.description){
var d = new bricks.Text({
otext:this.opts.description,
height:'auto',
i18n:true});
this.add_widget(d);
}
*/
this.form_body = new bricks.Layout({width:'100%',
overflow:'auto'
});
@ -72,9 +56,9 @@ bricks.FormBody = class extends bricks.VBox {
}
return data;
}
async validation(){
async validation(form){
var data = this.getValue();
this.dispatch('submit', data);
form.dispatch('submit', data);
if (this.submit_url){
var rc = new bricks.HttpResponse();
var resp = await rc.httpcall(this.submit_url,
@ -82,14 +66,19 @@ bricks.FormBody = class extends bricks.VBox {
method:this.method || 'POST',
params:data
});
this.dispatch('submited', resp);
form.dispatch('submited', resp);
}
}
build_fields(){
var fields = this.opts.fields;
for (var i=0; i<fields.length; i++){
var box = new bricks.VBox({height:'auto',overflow:'none'});
var box;
if (! this.opts.input_layout or this.opts.input_layout == 'VBox'){
box = new bricks.VBox({height:'auto',overflow:'none'});
} else {
box = new bricks.HBox({height:'auto',overflow:'none'});
}
box.set_css('inputbox');
this.form_body.add_widget(box);
var txt = new bricks.Text({
@ -114,10 +103,12 @@ bricks.Form = class extends bricks.VBox {
title:
description:
notoolbar:False,
input_layout:"VBox" or "HBox", default is "VBox",
cols:
dataurl:
toolbar:
submit_url:
method:
fields
}
*/
@ -138,15 +129,10 @@ bricks.Form = class extends bricks.VBox {
this.add_widget(d);
}
this.body = new bricks.FormBody(opts);
this.body.bind('submited', this.redispatch_submited.bind(this));
this.add_widget(this.body);
if (! opts.notoolbar)
this.build_toolbar(this);
}
redispatch_submited(event){
console.log('redispatch_submited():event=', event);
this.dispatch('submited', event.params);
}
build_toolbar(widget){
var box = new bricks.HBox({height:'auto', width:'100%'});
widget.add_widget(box);
@ -179,14 +165,14 @@ bricks.Form = class extends bricks.VBox {
return
}
if (params.name == 'submit'){
this.body.validation();
this.body.validation(this);
} else if (params.name == 'cancel'){
this.cancel();
} else if (params.name == 'reset'){
this.body.reset_data();
} else {
if (params.action){
f = buildEventHandler(this, params);
f = bricks.buildEventHandler(this, params);
if (f) f(event);
}
}