fix: UiFile multiple — resultValue/set_formdata support file arrays; Form required check handles arrays
This commit is contained in:
parent
55a7bce6e4
commit
235af19b2e
@ -336,7 +336,10 @@ bricks.FormBase = class extends bricks.Layout {
|
|||||||
|
|
||||||
var w = this.name_inputs[name];
|
var w = this.name_inputs[name];
|
||||||
var d = w.getValue();
|
var d = w.getValue();
|
||||||
if (w.required && ( d[name] == '' || d[name] === null)){
|
var val = d[name];
|
||||||
|
var empty = (val === '' || val === null || val === undefined ||
|
||||||
|
(Array.isArray(val) && val.length === 0));
|
||||||
|
if (w.required && empty){
|
||||||
bricks.debug('data=', data, 'd=', d);
|
bricks.debug('data=', data, 'd=', d);
|
||||||
new bricks.Error({title:bricks.app.i18n._('Requirement'), message:bricks.app.i18n._('required field must input') + '"' + w.label + '"'})
|
new bricks.Error({title:bricks.app.i18n._('Requirement'), message:bricks.app.i18n._('required field must input') + '"' + w.label + '"'})
|
||||||
w.focus();
|
w.focus();
|
||||||
@ -391,7 +394,10 @@ bricks.FormBase = class extends bricks.Layout {
|
|||||||
var w = this.name_inputs[name];
|
var w = this.name_inputs[name];
|
||||||
if (w.parent.is_disabled()) continue;
|
if (w.parent.is_disabled()) continue;
|
||||||
var d = w.getValue();
|
var d = w.getValue();
|
||||||
if (w.required && ( d[name] == '' || d[name] === null)){
|
var val = d[name];
|
||||||
|
var empty = (val === '' || val === null || val === undefined ||
|
||||||
|
(Array.isArray(val) && val.length === 0));
|
||||||
|
if (w.required && empty){
|
||||||
new bricks.Error({title:bricks.app.i18n._('Requirement'), message:bricks.app.i18n._('required field must input') + '"' + w.label + '"'})
|
new bricks.Error({title:bricks.app.i18n._('Requirement'), message:bricks.app.i18n._('required field must input') + '"' + w.label + '"'})
|
||||||
w.focus();
|
w.focus();
|
||||||
return;
|
return;
|
||||||
|
|||||||
@ -462,14 +462,25 @@ bricks.UiFile = class extends bricks.VBox {
|
|||||||
console.log('"changed" fired', this.getValue());
|
console.log('"changed" fired', this.getValue());
|
||||||
}
|
}
|
||||||
set_formdata(fd){
|
set_formdata(fd){
|
||||||
fd.append(this.name, this.resultValue());
|
var v = this.resultValue();
|
||||||
|
if (this.opts.multiple && Array.isArray(v)){
|
||||||
|
for (var i=0; i<v.length; i++){
|
||||||
|
fd.append(this.name, v[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fd.append(this.name, v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
resultValue(){
|
resultValue(){
|
||||||
if (this.value){
|
if (this.value){
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
if (this.input.files.length)
|
if (this.input.files.length){
|
||||||
|
if (this.opts.multiple){
|
||||||
|
return Array.from(this.input.files);
|
||||||
|
}
|
||||||
return this.input.files[0];
|
return this.input.files[0];
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
getValue(){
|
getValue(){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user