Skip to content

Commit

Permalink
Improved: Expansion of form widget field disabled atrribute with xsd …
Browse files Browse the repository at this point in the history
…improvement (#141)

(OFBIZ-10432)

1. Added disabled attribute support in ModelFormField with xs:boolean type
2. Removed specific field level disabled attribute support for CheckField and TextField
3. Modified existing usage of disabled attribute as per new implementation.

Thanks: Rishi for the report and Taher, Gil and Jacques for the feedback
  • Loading branch information
Pawan Verma committed May 19, 2020
1 parent ba463ab commit 3b7e637
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion applications/accounting/widget/InvoiceForms.xml
Expand Up @@ -513,7 +513,7 @@ under the License.
<field name="invoiceId"><hidden/></field>
<field name="paymentId"><lookup target-form-name="LookupPayment"/></field>
<field name="billingAccountId"><hidden/></field>
<field name="amountToApply"><text size="10" disabled="true"/></field>
<field name="amountToApply" disabled="true"><text size="10"/></field>
<field name="updateButton" title="${uiLabelMap.CommonUpdate}" widget-style="buttontext"><submit button-type="text-link"/></field>
<field name="removeButton" title=" " widget-style="buttontext" use-when="paymentApplicationId!=null">
<hyperlink description="${uiLabelMap.CommonRemove}" target="removeInvoiceApplication">
Expand Down
2 changes: 1 addition & 1 deletion applications/product/widget/catalog/ReviewForms.xml
Expand Up @@ -64,7 +64,7 @@ under the License.
<field name="statusId" title="${uiLabelMap.CommonStatus}"><display-entity entity-name="StatusItem"/></field>
<field name="userLoginId" title="${uiLabelMap.ProductReviewBy}" ><display/></field>
<field name="productRating" ignore-when="${statusId == 'PRR_DELETED'}"><text/></field>
<field name="productRating" ignore-when="${statusId != 'PRR_DELETED'}"><text disabled="true"/></field>
<field name="productRating" ignore-when="${statusId != 'PRR_DELETED'}" disabled="true"><text/></field>
<field name="productReview" ignore-when="${statusId == 'PRR_DELETED'}"><textarea/></field>
<field name="productReview" ignore-when="${statusId != 'PRR_DELETED'}"><textarea read-only="true"/></field>
<field name="submitButton" title="${uiLabelMap.CommonUpdate}" use-when="${statusId != 'PRR_DELETED'}"><submit button-type="button"/></field>
Expand Down
10 changes: 1 addition & 9 deletions framework/widget/dtd/widget-form.xsd
Expand Up @@ -840,6 +840,7 @@ under the License.
</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="disabled" type="xs:boolean" default="false"/>
</xs:complexType>
</xs:element>

Expand All @@ -852,14 +853,6 @@ under the License.
<xs:element ref="option" />
</xs:choice>
<xs:attribute name="all-checked" type="xs:boolean"/>
<xs:attribute name="disabled" default="false">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="true" />
<xs:enumeration value="false" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="container" substitutionGroup="AllFields">
Expand Down Expand Up @@ -1435,7 +1428,6 @@ under the License.
<xs:attribute type="xs:positiveInteger" name="size" default="25" />
<xs:attribute type="xs:positiveInteger" name="maxlength" />
<xs:attribute type="xs:string" name="default-value" />
<xs:attribute name="disabled" type="xs:boolean" default="false"/>
<xs:attribute name="client-autocomplete-field"
type="xs:boolean" default="true">
<xs:annotation>
Expand Down
Expand Up @@ -163,6 +163,7 @@ public static ModelFormField from(ModelFormFieldBuilder builder) {
private final String parentFormName;
private final String tabindex;
private final String conditionGroup;
private final boolean disabled;

private ModelFormField(ModelFormFieldBuilder builder) {
this.action = builder.getAction();
Expand Down Expand Up @@ -217,6 +218,7 @@ private ModelFormField(ModelFormFieldBuilder builder) {
this.parentFormName = builder.getParentFormName();
this.tabindex = builder.getTabindex();
this.conditionGroup = builder.getConditionGroup();
this.disabled = builder.getDisabled();
}

public FlexibleStringExpander getAction() {
Expand Down Expand Up @@ -487,6 +489,10 @@ public String getConditionGroup() {
return conditionGroup;
}

public boolean getDisabled() {
return disabled;
}

public Map<String, ? extends Object> getMap(Map<String, ? extends Object> context) {
if (UtilValidate.isEmpty(this.mapAcsr)) {
return this.modelForm.getDefaultMap(context);
Expand Down Expand Up @@ -1034,30 +1040,25 @@ public String getPartialSearch() {
public static class CheckField extends FieldInfoWithOptions {
public final static String ROW_SUBMIT_FIELD_NAME = "_rowSubmit";
private final FlexibleStringExpander allChecked;
private final boolean disabled;

private CheckField(CheckField original, ModelFormField modelFormField) {
super(original, modelFormField);
this.allChecked = original.allChecked;
this.disabled = original.disabled;
}

public CheckField(Element element, ModelFormField modelFormField) {
super(element, modelFormField);
allChecked = FlexibleStringExpander.getInstance(element.getAttribute("all-checked"));
this.disabled = "true".equals(element.getAttribute("disabled"));
}

public CheckField(int fieldSource, ModelFormField modelFormField) {
super(fieldSource, FieldInfo.CHECK, modelFormField);
this.allChecked = FlexibleStringExpander.getInstance("");
this.disabled = false;
}

public CheckField(ModelFormField modelFormField) {
super(FieldInfo.SOURCE_EXPLICIT, FieldInfo.CHECK, modelFormField);
this.allChecked = FlexibleStringExpander.getInstance("");
this.disabled = false;
}

@Override
Expand All @@ -1082,10 +1083,6 @@ public Boolean isAllChecked(Map<String, Object> context) {
return null;
}

public boolean getDisabled() {
return this.disabled;
}

@Override
public void renderFieldString(Appendable writer, Map<String, Object> context, FormStringRenderer formStringRenderer)
throws IOException {
Expand Down Expand Up @@ -4146,7 +4143,6 @@ public void renderFieldString(Appendable writer, Map<String, Object> context, Fo
public static class TextField extends FieldInfo {
private final boolean clientAutocompleteField;
private final FlexibleStringExpander defaultValue;
private final boolean disabled;
private final String mask;
private final Integer maxlength;
private final FlexibleStringExpander placeholder;
Expand All @@ -4158,7 +4154,6 @@ public TextField(Element element, ModelFormField modelFormField) {
super(element, modelFormField);
this.clientAutocompleteField = !"false".equals(element.getAttribute("client-autocomplete-field"));
this.defaultValue = FlexibleStringExpander.getInstance(element.getAttribute("default-value"));
this.disabled = "true".equals(element.getAttribute("disabled"));
this.mask = element.getAttribute("mask");
Integer maxlength = null;
String maxlengthStr = element.getAttribute("maxlength");
Expand Down Expand Up @@ -4196,7 +4191,6 @@ protected TextField(int fieldSource, int size, Integer maxlength, ModelFormField
super(fieldSource, fieldType == -1 ? FieldInfo.TEXT : fieldType, modelFormField);
this.clientAutocompleteField = true;
this.defaultValue = FlexibleStringExpander.getInstance("");
this.disabled = false;
this.mask = "";
this.maxlength = maxlength;
this.placeholder = FlexibleStringExpander.getInstance("");
Expand All @@ -4209,7 +4203,6 @@ protected TextField(int fieldSource, int size, Integer maxlength, ModelFormField
super(fieldSource, FieldInfo.TEXT, modelFormField);
this.clientAutocompleteField = true;
this.defaultValue = FlexibleStringExpander.getInstance("");
this.disabled = false;
this.mask = "";
this.maxlength = maxlength;
this.placeholder = FlexibleStringExpander.getInstance("");
Expand All @@ -4222,7 +4215,6 @@ private TextField(int fieldSource, int fieldType, ModelFormField modelFormField)
super(fieldSource, fieldType, modelFormField);
this.clientAutocompleteField = true;
this.defaultValue = FlexibleStringExpander.getInstance("");
this.disabled = false;
this.mask = "";
this.maxlength = null;
this.placeholder = FlexibleStringExpander.getInstance("");
Expand All @@ -4247,7 +4239,6 @@ protected TextField(TextField original, ModelFormField modelFormField) {
this.placeholder = original.placeholder;
this.size = original.size;
this.maxlength = original.maxlength;
this.disabled = original.disabled;
this.readonly = original.readonly;
if (original.subHyperlink != null) {
this.subHyperlink = new SubHyperlink(original.subHyperlink, modelFormField);
Expand Down Expand Up @@ -4281,10 +4272,6 @@ public String getDefaultValue(Map<String, Object> context) {
return "";
}

public boolean getDisabled() {
return this.disabled;
}

public String getMask() {
return this.mask;
}
Expand Down
Expand Up @@ -114,6 +114,7 @@ public class ModelFormFieldBuilder {
private String parentFormName = "";
private String tabindex = "";
private String conditionGroup = "";
private boolean disabled= false;

protected static final List<String> numericFieldTypes = Collections.unmodifiableList(UtilMisc.toList(
"floating-point", "numeric", "fixed-point",
Expand Down Expand Up @@ -203,6 +204,7 @@ public ModelFormFieldBuilder(Element fieldElement, ModelForm modelForm, ModelRea
this.parentFormName = fieldElement.getAttribute("form-name");
this.tabindex = fieldElement.getAttribute("tabindex");
this.conditionGroup = fieldElement.getAttribute("condition-group");
this.disabled = "true".equals(fieldElement.getAttribute("disabled"));
Element childElement = null;
List<? extends Element> subElements = UtilXml.childElementList(fieldElement);
for (Element subElement : subElements) {
Expand Down Expand Up @@ -319,6 +321,7 @@ public ModelFormFieldBuilder(ModelFormField modelFormField) {
this.parentFormName = modelFormField.getParentFormName();
this.tabindex = modelFormField.getTabindex();
this.conditionGroup = modelFormField.getConditionGroup();
this.disabled = modelFormField.getDisabled();
}

public ModelFormFieldBuilder(ModelFormFieldBuilder builder) {
Expand Down Expand Up @@ -361,6 +364,7 @@ public ModelFormFieldBuilder(ModelFormFieldBuilder builder) {
this.parentFormName = builder.getParentFormName();
this.tabindex = builder.getTabindex();
this.conditionGroup = builder.getConditionGroup();
this.disabled = builder.getDisabled();
}

public ModelFormFieldBuilder addOnChangeUpdateArea(UpdateArea onChangeUpdateArea) {
Expand Down Expand Up @@ -541,6 +545,10 @@ public String getConditionGroup() {
return conditionGroup;
}

public boolean getDisabled() {
return disabled;
}

private boolean induceFieldInfo(ModelForm modelForm, String defaultFieldType, ModelReader entityModelReader, DispatchContext dispatchContext) {
if (induceFieldInfoFromEntityField(defaultFieldType, entityModelReader)) {
return true;
Expand Down Expand Up @@ -825,6 +833,7 @@ public void mergeOverrideModelFormField(ModelFormFieldBuilder builder) {
this.position = builder.getPosition();
this.requiredField = builder.getRequiredField();
this.separateColumn = builder.getSeparateColumn();
this.disabled = builder.getDisabled();
}

public ModelFormFieldBuilder setAction(String action) {
Expand Down
Expand Up @@ -68,7 +68,6 @@ public void visit(CheckField checkField) throws Exception {
visitModelField(checkField.getModelFormField());
writer.append("<check");
visitAttribute("all-checked", checkField.getAllChecked());
visitAttribute("disabled", checkField.getDisabled());
visitFieldInfoWithOptions(checkField);
writer.append("</check></field>");
}
Expand Down Expand Up @@ -341,7 +340,6 @@ public void visit(TextFindField textField) throws Exception {
private void visitTextFieldAttrs(TextField field) throws Exception {
visitAttribute("client-autocomplete-field", field.getClientAutocompleteField());
visitAttribute("default-value", field.getDefaultValue());
visitAttribute("disabled", field.getDisabled());
visitAttribute("mask", field.getMask());
visitAttribute("maxlength", field.getMaxlength());
visitAttribute("placeholder", field.getPlaceholder());
Expand Down
Expand Up @@ -389,7 +389,7 @@ public void renderTextField(Appendable writer, Map<String, Object> context, Text
mask = textField.getMask();
}
String ajaxUrl = createAjaxParamsFromUpdateAreas(updateAreas, "", context);
boolean disabled = textField.getDisabled();
boolean disabled = modelFormField.getDisabled();
boolean readonly = textField.getReadonly();
String tabindex = modelFormField.getTabindex();
StringWriter sr = new StringWriter();
Expand Down Expand Up @@ -495,6 +495,7 @@ public void renderTextareaField(Appendable writer, Map<String, Object> context,
}
String tabindex = modelFormField.getTabindex();
String value = modelFormField.getEntry(context, textareaField.getDefaultValue(context));
boolean disabled = modelFormField.getDisabled();
StringWriter sr = new StringWriter();
sr.append("<@renderTextareaField ");
sr.append("name=\"");
Expand Down Expand Up @@ -523,7 +524,9 @@ public void renderTextareaField(Appendable writer, Map<String, Object> context,
sr.append(buttons);
sr.append("\" tabindex=\"");
sr.append(tabindex);
sr.append("\" />");
sr.append("\" disabled=");
sr.append(Boolean.toString(disabled));
sr.append(" />");
executeMacro(writer, sr.toString());
this.addAsterisks(writer, context, modelFormField);
this.appendTooltip(writer, context, modelFormField);
Expand All @@ -534,6 +537,7 @@ public void renderDateTimeField(Appendable writer, Map<String, Object> context,
ModelFormField modelFormField = dateTimeField.getModelFormField();
String paramName = modelFormField.getParameterName(context);
String defaultDateTimeString = dateTimeField.getDefaultDateTimeString(context);
boolean disabled = modelFormField.getDisabled();
String className = "";
String alert = "false";
String name = "";
Expand Down Expand Up @@ -770,7 +774,9 @@ public void renderDateTimeField(Appendable writer, Map<String, Object> context,
sr.append(formattedMask);
sr.append("\" tabindex=\"");
sr.append(tabindex);
sr.append("\" />");
sr.append("\" disabled=");
sr.append(Boolean.toString(disabled));
sr.append(" />");
executeMacro(writer, sr.toString());
this.addAsterisks(writer, context, modelFormField);
this.appendTooltip(writer, context, modelFormField);
Expand All @@ -782,6 +788,7 @@ public void renderDropDownField(Appendable writer, Map<String, Object> context,
ModelForm modelForm = modelFormField.getModelForm();
String currentValue = modelFormField.getEntry(context);
String conditionGroup = modelFormField.getConditionGroup();
boolean disabled = modelFormField.getDisabled();
List<ModelFormField.OptionValue> allOptionValues = dropDownField.getAllOptionValues(context, WidgetWorker.getDelegator(context));
ModelFormField.AutoComplete autoComplete = dropDownField.getAutoComplete();
String event = modelFormField.getEvent();
Expand Down Expand Up @@ -1012,7 +1019,9 @@ public void renderDropDownField(Appendable writer, Map<String, Object> context,
sr.append(conditionGroup);
sr.append("\" tabindex=\"");
sr.append(tabindex);
sr.append("\" />");
sr.append("\" disabled=");
sr.append(Boolean.toString(disabled));
sr.append(" />");
executeMacro(writer, sr.toString());
ModelFormField.SubHyperlink subHyperlink = dropDownField.getSubHyperlink();
if (subHyperlink != null && subHyperlink.shouldUse(context)) {
Expand All @@ -1027,7 +1036,7 @@ public void renderCheckField(Appendable writer, Map<String, Object> context, Che
String currentValue = modelFormField.getEntry(context);
String conditionGroup = modelFormField.getConditionGroup();
Boolean allChecked = checkField.isAllChecked(context);
boolean disabled = checkField.getDisabled();
boolean disabled = modelFormField.getDisabled();
String id = modelFormField.getCurrentContainerId(context);
String className = "";
String alert = "false";
Expand Down Expand Up @@ -1095,6 +1104,7 @@ public void renderRadioField(Appendable writer, Map<String, Object> context, Rad
List<ModelFormField.OptionValue> allOptionValues = radioField.getAllOptionValues(context, WidgetWorker.getDelegator(context));
String currentValue = modelFormField.getEntry(context);
String conditionGroup = modelFormField.getConditionGroup();
boolean disabled = modelFormField.getDisabled();
String className = "";
String alert = "false";
String name = modelFormField.getParameterName(context);
Expand Down Expand Up @@ -1146,7 +1156,9 @@ public void renderRadioField(Appendable writer, Map<String, Object> context, Rad
sr.append(conditionGroup);
sr.append("\" tabindex=\"");
sr.append(tabindex);
sr.append("\" />");
sr.append("\" disabled=");
sr.append(Boolean.toString(disabled));
sr.append(" />");
executeMacro(writer, sr.toString());
this.appendTooltip(writer, context, modelFormField);
}
Expand Down

0 comments on commit 3b7e637

Please sign in to comment.