Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort xPage multiline editBox by field converter?

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

like image 843
John Glabb Avatar asked Dec 01 '25 09:12

John Glabb


1 Answers

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>
like image 59
Knut Herrmann Avatar answered Dec 03 '25 23:12

Knut Herrmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!