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