flutter_dynamic_forms icon indicating copy to clipboard operation
flutter_dynamic_forms copied to clipboard

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

Open markphillips100 opened this issue 3 years ago • 4 comments

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?

markphillips100 avatar Apr 06 '21 03:04 markphillips100

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.

OndrejKunc avatar Apr 06 '21 07:04 OndrejKunc

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.

markphillips100 avatar Apr 06 '21 09:04 markphillips100

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).

OndrejKunc avatar Apr 06 '21 09:04 OndrejKunc

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.

markphillips100 avatar Apr 06 '21 10:04 markphillips100