Skip to content
Snippets Groups Projects

ENH: Add auto_focus and pattern to form_elements/form_panel

Merged Timm Fitschen requested to merge f-autofocus-pattern into dev
5 files
+ 70
4
Compare changes
  • Side-by-side
  • Inline

Files

+ 28
3
@@ -1337,14 +1337,26 @@ var form_elements = new function () {
return this._make_input(config);
}
/**
* Field config for a text field (config.type = 'text').
*
* @augments {FieldConfig}
*
* @property {string} pattern - a regex pattern which validates the value of the text field.
*/
/**
* Return a new text field.
*
* @param {FieldConfig} config
* @param {TextFieldConfig} config
* @return {HTMLElement}
*/
this.make_text_input = function (config) {
return this._make_input(config);
const input = this._make_input(config);
if (config.pattern) {
$(input).find("input").attr("pattern", config.pattern);
}
return input;
}
@@ -1528,6 +1540,19 @@ var form_elements = new function () {
}
/**
* Check form validity and return if the form is valid.
*
* @param {HTMLElement} form - the form elemeng.
* @return {boolean} true iff the form is valid.
*/
this.check_form_validity = function (form) {
const is_valid = form.checkValidity();
form.reportValidity();
return is_valid;
}
this.all_required_fields_set = function (form) {
const req = form_elements.get_enabled_required_fields(form);
for (const field of req) {
@@ -1542,7 +1567,7 @@ var form_elements = new function () {
* @param {HTMLElement} form - the form be validated.
*/
this.is_valid = function (form) {
return form_elements.all_required_fields_set(form);
return form_elements.all_required_fields_set(form) && form_elements.check_form_validity(form);
}
Loading