mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
webui: focus invalid widget on validation error
Reviewed-By: Fraser Tweedale <ftweedal@redhat.com> Reviewed-By: Endi Sukma Dewata <edewata@redhat.com>
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
define(['./ipa', './jquery', './navigation', './rpc', './text', './field', './widget', './dialog'],
|
||||
function(IPA, $, navigation, rpc, text) {
|
||||
function(IPA, $, navigation, rpc, text, field_mod, widget_mod) {
|
||||
|
||||
/**
|
||||
* Entity adder dialog
|
||||
@@ -219,7 +219,10 @@ IPA.entity_adder_dialog = function(spec) {
|
||||
*/
|
||||
that.add = function(on_success, on_error) {
|
||||
|
||||
if (!that.validate()) return;
|
||||
if (!that.validate()) {
|
||||
widget_mod.focus_invalid(that);
|
||||
return;
|
||||
}
|
||||
|
||||
var record = {};
|
||||
that.save(record);
|
||||
|
||||
@@ -31,9 +31,10 @@ define([
|
||||
'./rpc',
|
||||
'./spec_util',
|
||||
'./text',
|
||||
'./widget',
|
||||
'./facet',
|
||||
'./add'],
|
||||
function(lang, builder, IPA, $, phases, reg, rpc, su, text) {
|
||||
function(lang, builder, IPA, $, phases, reg, rpc, su, text, widget_mod) {
|
||||
|
||||
/**
|
||||
* Details module
|
||||
@@ -1436,6 +1437,7 @@ exp.update_action = IPA.update_action = function(spec) {
|
||||
|
||||
if (!facet.validate()) {
|
||||
facet.show_validation_error();
|
||||
widget_mod.focus_invalid(facet);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -5755,6 +5755,28 @@ exp.activity_widget = IPA.activity_widget = function(spec) {
|
||||
return that;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find and focus first focusable invalid widget
|
||||
* @member widget
|
||||
* @param {IPA.widget|facet.facet} widget Widget container
|
||||
* @return {boolean} A widget was focused
|
||||
*/
|
||||
exp.focus_invalid = function(widget) {
|
||||
|
||||
var widgets = widget.widgets.widgets;
|
||||
var focused = false;
|
||||
for (var i=0, l=widgets.length; i<l; i++) {
|
||||
var w = widgets.values[i];
|
||||
if (w.valid === false && w.focus_input) {
|
||||
w.focus_input();
|
||||
focused = true;
|
||||
}
|
||||
else if (w.widgets) focused = exp.focus_invalid(w);
|
||||
if (focused) break;
|
||||
}
|
||||
return focused;
|
||||
};
|
||||
|
||||
/**
|
||||
* pre_op operations for widgets
|
||||
* - sets facet and entity if present in context
|
||||
|
||||
Reference in New Issue
Block a user