Skip to content

Commit

Permalink
Improved: Adds support for textarea placeholder attribute, using a Fl…
Browse files Browse the repository at this point in the history
…exibleStringExpander (OFBIZ-12859)

With this PR we can add a "placeholder" attribute on "textarea" field widget. This attribute can be dynamic (FlexibleStringExpander). Its content is added in a "placeholder" attribute on the HTML textarea (https://developer.mozilla.org/fr/docs/Web/HTML/Element/textarea#placeholder).

Thanks: Florian Motteau
  • Loading branch information
florianMo authored and MkLeila committed Nov 24, 2023
1 parent 577e968 commit 9935270
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 6 deletions.
7 changes: 7 additions & 0 deletions framework/widget/dtd/widget-form.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,13 @@ under the License.
table clean html spellcheck |(separator) Default is that all buttons are shown</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute type="xs:string" name="placeholder">
<xs:annotation>
<xs:documentation>
Content of the HTML placeholder attribute (https://developer.mozilla.org/fr/docs/Web/HTML/Element/textarea#placeholder), text to be displayed to the user when textarea is empty. Similar to text input placeholder.
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="text-find" substitutionGroup="AllFields">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5074,6 +5074,7 @@ public static class TextareaField extends FieldInfo {
private final FlexibleStringExpander visualEditorButtons;
private final boolean visualEditorEnable;
private final Integer maxlength;
private final FlexibleStringExpander placeholder;

public TextareaField(Element element, ModelFormField modelFormField) {
super(element, modelFormField);
Expand Down Expand Up @@ -5114,6 +5115,7 @@ public TextareaField(Element element, ModelFormField modelFormField) {
this.maxlength = maxlength;
this.visualEditorButtons = FlexibleStringExpander.getInstance(element.getAttribute("visual-editor-buttons"));
this.visualEditorEnable = "true".equals(element.getAttribute("visual-editor-enable"));
this.placeholder = FlexibleStringExpander.getInstance(element.getAttribute("placeholder"));
}

public TextareaField(int fieldSource, ModelFormField modelFormField) {
Expand All @@ -5125,6 +5127,7 @@ public TextareaField(int fieldSource, ModelFormField modelFormField) {
this.maxlength = null;
this.visualEditorButtons = FlexibleStringExpander.getInstance("");
this.visualEditorEnable = false;
this.placeholder = FlexibleStringExpander.getInstance("");
}

public TextareaField(ModelFormField modelFormField) {
Expand All @@ -5140,6 +5143,7 @@ private TextareaField(TextareaField original, ModelFormField modelFormField) {
this.cols = original.cols;
this.rows = original.rows;
this.maxlength = original.maxlength;
this.placeholder = original.placeholder;
}

@Override
Expand Down Expand Up @@ -5229,6 +5233,22 @@ public boolean isReadOnly() {
return readOnly;
}

/**
* Returns the placeholder
* @return the placeholder
*/
public FlexibleStringExpander getPlaceholder() {
return this.placeholder;
}

/**
* Returns the placeholder
* @return the placeholder
*/
public String getPlaceholder(Map<String, Object> context) {
return this.placeholder.expandString(context);
}

@Override
public void renderFieldString(Appendable writer, Map<String, Object> context, FormStringRenderer formStringRenderer)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ public void visit(TextareaField textareaField) throws Exception {
visitAttribute("rows", textareaField.getRows());
visitAttribute("visual-editor-buttons", textareaField.getVisualEditorButtons());
visitAttribute("visual-editor-enable", textareaField.getVisualEditorEnable());
visitAttribute("placeholder", textareaField.getPlaceholder());
writer.append("/></field>");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ public RenderableFtl textArea(final Map<String, Object> context, final ModelForm
builder.intParameter("maxlength", textareaField.getMaxlength());
}

builder.stringParameter("placeholder", textareaField.getPlaceholder(context));

builder.stringParameter("tabindex", modelFormField.getTabindex());

builder.stringParameter("value", modelFormField.getEntry(context, textareaField.getDefaultValue(context)));
Expand Down
2 changes: 1 addition & 1 deletion themes/common-theme/template/macro/CsvFormMacroLibrary.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ under the License.

<#macro renderTextField name className alert value textSize maxlength id event action disabled clientAutocomplete ajaxUrl ajaxEnabled mask tabindex readonly placeholder="" delegatorName="default"><@renderField value /></#macro>

<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false></#macro>
<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false placeholder=""></#macro>

<#macro renderDateTimeField name className timeDropdownParamName defaultDateTimeString localizedIconTitle timeHourName timeMinutesName ampmName compositeType alert=false isTimeType=false isDateType=false amSelected=false pmSelected=false timeDropdown="" classString="" isTwelveHour=false hour1="" hour2="" minutes=0 shortDateInput="" title="" value="" size="" maxlength="" id="" formName="" mask="" event="" action="" step="" timeValues="" tabindex="" disabled=false isXMLHttpRequest=false><@renderField value /></#macro>

Expand Down
2 changes: 1 addition & 1 deletion themes/common-theme/template/macro/FoFormMacroLibrary.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ under the License.

<#macro renderTextField name className alert value textSize maxlength id event action disabled clientAutocomplete ajaxUrl ajaxEnabled mask tabindex readonly placeholder="" delegatorName="default"><@makeBlock className value /></#macro>

<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false><@makeBlock className value /></#macro>
<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false placeholder=""><@makeBlock className value /></#macro>

<#macro renderDateTimeField name className timeDropdownParamName defaultDateTimeString localizedIconTitle timeHourName timeMinutesName ampmName compositeType alert=false isTimeType=false isDateType=false amSelected=false pmSelected=false timeDropdown="" classString="" isTwelveHour=false hour1="" hour2="" minutes=0 shortDateInput="" title="" value="" size="" maxlength="" id="" formName="" mask="" event="" action="" step="" timeValues="" tabindex="" disabled=false isXMLHttpRequest=false><@makeBlock className value /></#macro>

Expand Down
3 changes: 2 additions & 1 deletion themes/common-theme/template/macro/HtmlFormMacroLibrary.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ under the License.
/><#t/>
</#macro>

<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false>
<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false placeholder="">
<#if visualEditorEnable?has_content>
<#local className = className + " visual-editor">
</#if>
Expand All @@ -83,6 +83,7 @@ under the License.
<#if tabindex?has_content> tabindex="${tabindex}"</#if><#rt/>
<#if visualEditorEnable?has_content> data-toolbar="${buttons?default("maxi")}"</#if><#rt/>
<#if language?has_content> data-language="${language!"en"}"</#if><#rt/>
<#if placeholder?has_content> placeholder="${placeholder}"</#if><#rt/>
><#t/>
<#if value?has_content>${value}</#if><#t/>
</textarea><#lt/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ under the License.

<#macro renderTextField name className alert value textSize maxlength id event action disabled clientAutocomplete ajaxUrl ajaxEnabled mask tabindex readonly placeholder="" delegatorName="default"><@renderField value /></#macro>

<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false><@renderField value /></#macro>
<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false placeholder=""><@renderField value /></#macro>

<#macro renderDateTimeField name className alert title value size maxlength id dateType shortDateInput timeDropdownParamName defaultDateTimeString localizedIconTitle timeDropdown timeHourName classString hour1 hour2 timeMinutesName minutes isTwelveHour ampmName amSelected pmSelected compositeType formName mask="" event="" action="" step="" timeValues="" tabindex="" disabled="" isXMLHttpRequest=""><@renderField value /></#macro>

Expand Down
2 changes: 1 addition & 1 deletion themes/common-theme/template/macro/XlsFormMacroLibrary.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ under the License.

<#macro renderTextField name className alert value textSize maxlength id event action disabled clientAutocomplete ajaxUrl ajaxEnabled mask tabindex readonly placeholder="" delegatorName="default"><@renderItemField value "txf" className/></#macro>

<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false></#macro>
<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false placeholder=""></#macro>

<#macro renderDateTimeField name className timeDropdownParamName defaultDateTimeString localizedIconTitle timeHourName timeMinutesName ampmName compositeType alert=false isTimeType=false isDateType=false amSelected=false pmSelected=false timeDropdown="" classString="" isTwelveHour=false hour1="" hour2="" minutes=0 shortDateInput="" title="" value="" size="" maxlength="" id="" formName="" mask="" event="" action="" step="" timeValues="" tabindex="" disabled=false isXMLHttpRequest=false>
<#if isTimeType ><@renderItemField value "tf" className/>
Expand Down
2 changes: 1 addition & 1 deletion themes/common-theme/template/macro/XmlFormMacroLibrary.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ under the License.

<#macro renderTextField name className alert value textSize maxlength id event action disabled clientAutocomplete ajaxUrl ajaxEnabled mask tabindex readonly placeholder="" delegatorName="default"><@renderField value/></#macro>

<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false><@renderField value/></#macro>
<#macro renderTextareaField name className alert cols="" rows="" maxlength="" id="" readonly="" value="" visualEditorEnable="" buttons="" tabindex="" language="" disabled=false placeholder=""><@renderField value/></#macro>

<#macro renderDateTimeField name className timeDropdownParamName defaultDateTimeString localizedIconTitle timeHourName timeMinutesName ampmName compositeType alert=false isTimeType=false isDateType=false amSelected=false pmSelected=false timeDropdown="" classString="" isTwelveHour=false hour1="" hour2="" minutes=0 shortDateInput="" title="" value="" size="" maxlength="" id="" formName="" mask="" event="" action="" step="" timeValues="" tabindex="" disabled=false isXMLHttpRequest=false><@renderField value/></#macro>

Expand Down

0 comments on commit 9935270

Please sign in to comment.