B4J Question [ABMaterial] ABMCombo hates ' in inputtext argument

Dan Haugland

Member
Licensed User
In the demo, module CompComboPage change this line:
B4X:
    combo1.AddItem("combo1S1", "Mom", BuildSimpleItem("S1", "mdi-action-account-circle", "{NBSP}{NBSP}Mom"))

to this:
B4X:
    combo1.AddItem("combo1S1", "Mom's", BuildSimpleItem("S1", "mdi-action-account-circle", "{NBSP}{NBSP}Mom"))

And you can no longer select this item. It exists in the combobox list of possibilities, but cannot be selected. Doing something wrong, or is there a workaround?

Update: Found a way around it, disregard.
 
Last edited:

Harris

Expert
Licensed User
Longtime User
In the demo, module CompComboPage change this line:
B4X:
    combo1.AddItem("combo1S1", "Mom", BuildSimpleItem("S1", "mdi-action-account-circle", "{NBSP}{NBSP}Mom"))

to this:
B4X:
    combo1.AddItem("combo1S1", "Mom's", BuildSimpleItem("S1", "mdi-action-account-circle", "{NBSP}{NBSP}Mom"))

And you can no longer select this item. It exists in the combobox list of possibilities, but cannot be selected. Doing something wrong, or is there a workaround?

Update: Found a way around it, disregard.

Please explain how...
How we all hate when this type of response is provided without the "How To" in the same statement.
I can imagine how a single quote ' would cause havoc, but how did you "find a way around it"...
Tomorrow, I (and others) may do the same thing and be at a complete loss as how to overcome this... even thou it was already solved...
We all learn (and grow) from everyone's endeavor's.

Thanks kindly.
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
The trouble with 'workarounds' is that they can get you into problems later once the bug is fixed. Here is what happened:

The scenario:
You write code in B4J which writes Java code that writes ABMaterial HTML and Javascript code.

The issue:
As you know, strings have to be between quotes. This means trouble on every language level. Erel solved this very elegant by giving us smart strings $""$. On the ABMaterial level (HTML, Javascript I don't have that luck). So 'writing' a line of HTML code can become very ugly very fast. In case of the combo, the end result had to be something like this:

B4X:
<div onclick="comboclickarray(event, '', '', 'clientcombo', 'Mom', '3')" id="clientcombo3" style="border-bottom: 1px solid #9e9e9e">

You can see the cluster of double and single quotes. So when inputText became Mom's, the bugged code was written as:

B4X:
<div onclick="comboclickarray(event, '', '', 'clientcombo', 'Mom's', '3')" id="clientcombo3" style="border-bottom: 1px solid #9e9e9e">

And this is of course illegal code.

The workaround the OP used was escaping the ' in Mom's so wrote in B4J (and this works as it is what ABMaterial needed to do):

B4X:
C.AddItem("2", "Mom\'s",bldItem("2-L","Mom's"))

But now the bug is fixed, he will not get the desired result anymore: Mom\'s will stay Mom\'s and not become Mom's.

Just to give you an idea of the ugliness ABMaterial has to deal with (and why I somehow missed one level of quotes), here is my line of code in the ABMaterial library:

B4X:
s.append("<div onclick=\"comboclickarray(event, '" + ParentString + "','" + ArrayName.toLowerCase() + "','" + ArrayName.toLowerCase() + ID.toLowerCase() + "','" + entry.getValue().inputText.replace("\\","\\\\").replace("'", "\\\'").replace("\"", "&quot;") + "','" + entry.getValue().returnId + "')\" id=\"" + ParentString + ArrayName.toLowerCase() + ID.toLowerCase() + entry.getValue().returnId + "\" style=\"border-bottom: 1px solid " + ABMaterial.GetColorStrMap(l.ItemDividerColor, l.ItemDividerColorIntensity) + "\">\n"); // + ";padding: 0px 1rem;\">\n");

So, not only has it to deal with the quote problem described above, it has its own quote escaping (and escaping of escaped characters) to do.

I hope this gives you some insight in what happened and why it is very important this stuff is entered in the Feedback app.

Cheers,

Alain
 
Upvote 0

Harris

Expert
Licensed User
Longtime User
B4X:
Sub SetQuotes(str As String) As String
    str = ABMShared.ReplaceAll(str, "'", "''")
    Return "'" & str & "'"   
End Sub

I see this sub in DBM used for the same purpose essentially?
Thanks
 
Upvote 0
Top