refactor client-side form is not valid/submittable check of submit method into an own method isInvalid()

This commit is contained in:
Ralf Becker 2021-09-30 09:26:36 +02:00
parent fb88f8846b
commit db83cc437c

View File

@ -839,6 +839,38 @@ export class etemplate2
}
}
/**
* Check if there is an invalid widget / all widgets are valid
*
* @param container
* @param values
* @return et2_widget|null first invalid widget or null, if all are valid
*/
isInvalid(container : et2_container|undefined, values : object|undefined) : et2_widget|null
{
if (typeof container === 'undefined')
{
container = this._widgetContainer;
}
if (typeof values === 'undefined')
{
values = this.getValues(container);
}
let invalid = null;
container.iterateOver(function (_widget)
{
if (_widget.submit(values) === false)
{
if(!invalid && !_widget.isValid([]))
{
invalid = _widget;
}
}
}, this, et2_ISubmitListener);
return invalid;
}
/**
* Submit form via ajax
*
@ -867,17 +899,7 @@ export class etemplate2
let invalid = null;
if (!no_validation)
{
container.iterateOver(function (_widget)
{
if (_widget.submit(values) === false)
{
if(!invalid && !_widget.isValid())
{
invalid = _widget;
}
canSubmit = false;
}
}, this, et2_ISubmitListener);
canSubmit = !(invalid = this.isInvalid(container, values));
}
if (canSubmit)
@ -1082,7 +1104,6 @@ export class etemplate2
return result;
}
/**
* "Intelligently" refresh the template based on the given ID
*