I have multiline Edit Box on my page. I want a converter that converts entered text into a list (replaces e.g. comas with new line) then do @Unique and finally sort on save. Here is my code that doesn't work:
<xp:inputTextarea value="#{document1.Members}" id="inputMembers" multipleTrim="true" immediate="true">
<xp:this.multipleSeparator><![CDATA[#{javascript:"\n"}]]></xp:this.multipleSeparator>
<xp:this.converter>
<xp:customConverter>
<xp:this.getAsObject><![CDATA[#{javascript:@Unique(value).sort();}]]></xp:this.getAsObject>
<xp:this.getAsString><![CDATA[#{javascript:@ReplaceSubString(value, ",", "\n");}]]></xp:this.getAsString>
</xp:customConverter>
</xp:this.converter>
it does replace comas with new line but doesn't sort the list
Don't use the multipleSeparator property. Otherwise, getAsObject converter is executed for every entry (=line) separately. That's why sort doesn't work.
Implode the entries with "\n" instead when converting value for browser (getAsString) and explode multiple lines and comma separated values when getting back lines from browser (getAsObject) and sort the resulting array:
<xp:inputTextarea
value="#{document1.Members}"
id="inputMembers"
rows="10">
<xp:this.converter>
<xp:customConverter>
<xp:this.getAsObject><![CDATA[#{javascript:
@Unique(@Trim(@Explode(value, ["\n", ","]))).sort()
}]]></xp:this.getAsObject>
<xp:this.getAsString><![CDATA[#{javascript:
@Implode(value, "\n")
}]]></xp:this.getAsString>
</xp:customConverter>
</xp:this.converter>
</xp:inputTextarea>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With