B4J Question [Solved] [ABMaterial] ABMInput with currency values

Xandoca

Active Member
Licensed User
Longtime User
Hi,

I've try to use ABMInput for a currency field (price). I've try with ABM.input_number but I could see that it's an integer number.
Then I try with ABM.INPUT_TEXT with inputMask ("'mask': '999,99'") but when the page is loaded appears "___,__" at input field. And also user should be able to enter 10,10 or 100,10.
Should I implement a validate function for this currency field (check if it is in correct format) or there is another better approach to work with currency input fields using ABMaterial framework?

Regards.
 

alwaysbusy

Expert
Licensed User
Longtime User
There have always been problems with the library I implemented for the InputMask. It just has to many bugs in them, especially with the placeholder and how the cursor behaves. (I think as of today it has 450+ open issues on github). And the mask syntax is just horrible. But 4 years ago, this was about the best one around. There are plans to completely replace it in a future version with another one (if I can find a good one, but even now in 2020, this one seems to be the best one around). In the mean time, I thing B4JS 'may' be helpful here, but it will not be easy to write.
 
Upvote 0

Xandoca

Active Member
Licensed User
Longtime User
Using changed event and the code below (thanks to @mc73 code) I got a good solution (at least for me šŸ˜œ).

currencyfield.gif


B4X:
Sub inputtaxahora_Changed(value As String)
    
    Dim tempString As String
    tempString=value.Replace (".","")
    Dim tempval As Double
    tempval=tempString/100

    Dim decimalplaces As String = ""   
    If tempval <> user.taxahora Then
        Dim input As ABMInput = page.Component("inputtaxahora")
        tempString = tempval
        If tempString.IndexOf(".")>0 Then
            If (tempString.Length - tempString.IndexOf(".")) = 2 Then
                decimalplaces = "0"
            End If
        Else
            decimalplaces = ".00"
        End If
        
        input.Text=tempval & decimalplaces
        user.taxahora = tempval & decimalplaces
        
        input.Refresh
    End If
    
End Sub

Thank you all.
 
Upvote 0
Top