beagle: eq doesn't work
Please provide all the information requested. Issues that do not follow this format are likely to stall.
Description
Please provide a clear and concise description of what the bug is. Include screenshots if needed. Please test using the latest Beagle release to make sure your issue has not already been fixed: https://github.com/ZupIT/beagle/releases
Steps To Reproduce
Provide a detailed list of steps that reproduce the issue.
- Launch the playground
- Run conditional-action.json with modification: replace gte function with eq function …
"onPress": [
{
"_beagleAction_": "beagle:condition",
"condition": "@{eq(user.age, 18)}",
"onTrue": [
{
…
Expected Results
Setting the age to 18 will result buying a beer.
What actually happen: never able to buy a beer.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (9 by maintainers)
Hi @TomerPacific. We really appreciate your help, but we need this feature asap. For this reason, @hernandazevedozup will pick this up from where you left it.
@TomerPacific This will depend on the language you’re using. If the language can sum
Int
andDouble
and give you aDouble
result, then you don’t need to do anything else, the language itself made these conversions under the hood for you.In the case of Kotlin, you can ignore this statement (line 2).
@TomerPacific Thank you very much for the contribution, the feedback is here https://github.com/ZupIT/beagle-android/pull/106#issuecomment-1289360297
@TomerPacific tyvm for your contribution. I’ll ask @hernandazevedozup to take a look and get back to you asap!
Hi @Tiagoperes , would you like help with this issue?
Added to the backlog:
1. Make the following operations agnostic to the type of the data:
eq
,gt
,lt
,gte
,lte
..
as the decimal part separator. If there’s a parse error, return false.2. Make the following operations agnostic to the type of the data:
sum
,subtract
,multiply
,divide
.divide
; a double if at least one of the arguments is a double or a string representing a double; an integer otherwise..
as the decimal separator.3. Create operations to convert types:
int(String)
: parses the String into an integer (decimal). On parse error return NaN, if supported, or null otherwise.int(Double)
: converts the Double into an Integer by truncating its decimal part.double(String)
: parses the String into a double (decimal,.
as the separator). On parse error return NaN, if supported, or null otherwise.double(Int)
: converts the Integer into a Double.string(Int)
: creates a string representation of the integer.string(Double)
: creates a string representation of the double (.
as the separator).Platforms
1
and2
should be implemented on Android and iOS.3
should also be implemented on web platforms.Hi @brianchu, hope you’re ok!
I figured you’re referring to this example: https://playground.usebeagle.io/#/demo/component-interaction/condional-action.json?platform=ios
I checked and there’s a bug with Beagle Android and Beagle iOS. The comparison operations should make automatic type coercions. It gives you false because the string “18” is not equal to the integer 18. It is a string because the value comes from a text field.
We’ll fix this to make every comparison function auto coerce Strings to Int or Doubles if they represent these types, but while this is not fixed, you can use a custom operation as a workaround.
You can either create a custom operation
eq
with type coercion or implement an operation that converts string to Int.Example of the second:
eq(int(user.age), 18)
.Documentation for custom operations: https://docs.usebeagle.io/v2.0/api/operations/how-to-register-a-new-operation/