Form widget improvement: Set focus on first control when rendering a single form.
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1650357 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -89,12 +89,22 @@ public class FormRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFocusFieldName(ModelForm modelForm, Map<String, Object> context) {
|
||||
String focusFieldName = (String) context.get(modelForm.getName().concat(".focusFieldName"));
|
||||
if (focusFieldName == null) {
|
||||
return "";
|
||||
}
|
||||
return focusFieldName;
|
||||
}
|
||||
|
||||
private final ModelForm modelForm;
|
||||
private final FormStringRenderer formStringRenderer;
|
||||
private String focusFieldName;
|
||||
|
||||
public FormRenderer(ModelForm modelForm, FormStringRenderer formStringRenderer) {
|
||||
this.modelForm = modelForm;
|
||||
this.formStringRenderer = formStringRenderer;
|
||||
this.focusFieldName = modelForm.getFocusFieldName();
|
||||
}
|
||||
|
||||
private Collection<List<ModelFormField>> getFieldListsByPosition(List<ModelFormField> modelFormFieldList) {
|
||||
@@ -111,6 +121,10 @@ public class FormRenderer {
|
||||
return fieldsByPosition.values();
|
||||
}
|
||||
|
||||
public String getFocusFieldName() {
|
||||
return focusFieldName;
|
||||
}
|
||||
|
||||
private List<ModelFormField> getHiddenIgnoredFields(Map<String, Object> context, Set<String> alreadyRendered,
|
||||
List<ModelFormField> fieldList, int position) {
|
||||
/*
|
||||
@@ -1093,6 +1107,15 @@ public class FormRenderer {
|
||||
continue;
|
||||
}
|
||||
alreadyRendered.add(currentFormField.getName());
|
||||
if (focusFieldName.isEmpty()) {
|
||||
if (fieldInfo.getFieldType() != FieldInfo.DISPLAY && fieldInfo.getFieldType() != FieldInfo.HIDDEN
|
||||
&& fieldInfo.getFieldType() != FieldInfo.DISPLAY_ENTITY
|
||||
&& fieldInfo.getFieldType() != FieldInfo.IGNORED
|
||||
&& fieldInfo.getFieldType() != FieldInfo.IMAGE) {
|
||||
focusFieldName = currentFormField.getName();
|
||||
context.put(modelForm.getName().concat(".focusFieldName"), focusFieldName);
|
||||
}
|
||||
}
|
||||
|
||||
boolean stayingOnRow = false;
|
||||
if (lastFormField != null) {
|
||||
|
||||
@@ -1347,7 +1347,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
}
|
||||
|
||||
public void renderFormClose(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
|
||||
String focusFieldName = modelForm.getfocusFieldName();
|
||||
String focusFieldName = FormRenderer.getFocusFieldName(modelForm, context);
|
||||
String formName = FormRenderer.getCurrentFormName(modelForm, context);
|
||||
String containerId = FormRenderer.getCurrentContainerId(modelForm, context);
|
||||
String hasRequiredField = "";
|
||||
|
||||
@@ -730,12 +730,8 @@ public class ModelForm extends ModelWidget {
|
||||
sortOrderFields.trimToSize();
|
||||
this.sortOrderFields = Collections.unmodifiableList(sortOrderFields);
|
||||
String focusFieldName = formElement.getAttribute("focus-field-name");
|
||||
if (focusFieldName.isEmpty()) {
|
||||
if (parentModelForm != null) {
|
||||
focusFieldName = parentModelForm.focusFieldName;
|
||||
} else {
|
||||
// TODO: Set this automatically if not specified
|
||||
}
|
||||
if (focusFieldName.isEmpty() && parentModelForm != null) {
|
||||
focusFieldName = parentModelForm.focusFieldName;
|
||||
}
|
||||
this.focusFieldName = focusFieldName;
|
||||
}
|
||||
@@ -1006,10 +1002,6 @@ public class ModelForm extends ModelWidget {
|
||||
return fieldList;
|
||||
}
|
||||
|
||||
public String getfocusFieldName() {
|
||||
return this.focusFieldName;
|
||||
}
|
||||
|
||||
public String getFocusFieldName() {
|
||||
return focusFieldName;
|
||||
}
|
||||
|
||||
@@ -1223,7 +1223,7 @@ public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRe
|
||||
*/
|
||||
public void renderFormClose(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
|
||||
writer.append("</form>");
|
||||
String focusFieldName = modelForm.getfocusFieldName();
|
||||
String focusFieldName = FormRenderer.getFocusFieldName(modelForm, context);
|
||||
if (UtilValidate.isNotEmpty(focusFieldName)) {
|
||||
appendWhitespace(writer);
|
||||
writer.append("<script language=\"JavaScript\" type=\"text/javascript\">");
|
||||
|
||||
Reference in New Issue
Block a user