OndrejKunc / flutter_dynamic_forms

A collection of flutter and dart libraries allowing you to consume complex external forms at runtime.
MIT License
204 stars 60 forks source link

Form element with Id containing '-' character outputs warning? #97

Open markphillips100 opened 3 years ago

markphillips100 commented 3 years ago

I have form elements with hyphens ('-') in their Id's text as a word separator but this also applies if the Id were a guid. The latest null-safe release (1.0.0) now outputs a warning message indicating the following:

"Only alphanumerics characters and underscores are allowed and identifiers cannot start with a number".

Is there a specific reason a guid would not be allowed for an Id?

OndrejKunc commented 3 years ago

Yes, this can be a problem in the current implementation when referencing this id in an expression.

Since the beginning, there is a possibility to write expressions like @elementId.property but also @elementId without specifying the property and in that case, it will look for a property named value. This was supposed to be syntactic sugar since most of our components had a property called value. I no longer find this shortcut very useful because it can be more harmful than beneficial.

The problem is the conflict with the minus operator. Consider this expression:

@50b1b9b3-1601-4b58-bcf5-54a1cc9e362f

In this case, it is not clear if there is an id 50b1b9b3 and you want to subtract the number 1601 or if the whole string is a guid.

It can be solved by getting rid of the value syntactic sugar so the grammar parser will always look for the dot after the identifier. In that case, we would also need to have a different set of characters for the property names, because there will be the same issue with the minus operator.

Hopefully, this answered your question. We can keep this issue opened until I will remove this syntactic sugar (if it really turns out nobody uses it) and change the grammar so it will allow those characters.

markphillips100 commented 3 years ago

Thanks @OndrejKunc for the detail. If I'm understanding correctly this only becomes an issue if using the Id in a string expression specifically? So if I were only using expression tree code as I am currently doing, rather than parsed string expressions then I can still use guids for the Ids? I haven't tried yet but will soon just to see if I hit a roadblock.

OndrejKunc commented 3 years ago

I think so. The problem is in the parser which converts String to an expression tree. If you don't use the id in this String or you construct the expression tree by yourself it should be fine (unless I am forgetting something).

markphillips100 commented 3 years ago

Thanks @OndrejKunc . I'll see how I go and post back here should I have an issue I can't think of right now, if you don't mind keeping this one open for now that is.