-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do we temporarilly allow invalid input with a databinding? #670
Comments
In my view, it makes a lot of sense to use a By the way, you can also use the |
I don't have much GUI programming experience, so I may be wrong, but "data binding" to me means to bind domain-specific data to GUI elements, so the data is suitable to be directly used by business logic. Imagine we bind a text input to I think my trouble comes from the two-way binding, so I'm trying to break it up, using a data view and a event callback. In the callback I could validate the input and update the data as appropriate. This works well, but the initial value of the data will be reflected in the text input, and I haven't figure out how to have an empty text input in the first place.
I've tried and this is really cool, Thanks! but I found myself lacking in understanding of data and its presentation in the UI. For example, how does RmlUi handle the converting between an integer and the value in text input? I'm guessing something like Also, I once bind a data attribute to a boolean value, and found I have to use selectors like This may be obvious to you, so I'm sorry to take up your time. I'd like to make a PR to the RmlUi documentation once I'm clear on this to help other users. |
Thanks for updating the documentation by the way! Hopefully things are a bit more clear for the next user that comes along :) I would say more generally, I think it's quite common to have some logic sitting between the actual business data, and the UI data. Even just for the sake of threading, one often keeps a UI copy of the data for the UI thread. And it is not uncommon to see cached results for presenting to the UI, for performance sake. Maybe these can be considered deviations from the "ideal" though, which is that there is one true source of data. But I don't know, I certainly don't have any final say either way. I think generally, it's a bit problematic that the state of the view contains more information than the model (i.e. invalid characters). At least, at some point in the pipeline, we need some way to express and display input values that are intermittently invalid. Maybe ideally that logic would be part of an e.g. All of that aside, maybe you can make it behave the way you want with custom getters and setters. I'd be interested to see what ends up working for you. |
I'm still trying in the "one true source of data" direction. Maybe it's just because I haven't really got into multi-threading programming yet, but I think I've found a solution that works for me. I'll explain it below. "One-way" bindingI am mainly using "one-way" binding, which is to set up a data view of the data, and modify the data (and mark it as dirty) by a callback. This is for 2 reasons:
I found this approach give me much freedom to do whatever I want in the callback. And if I want to view the same piece of data in slightly differently ways, I could use Domain data and UI dataThese may not be the best names but is what I'm using now. Let's take the date example again. The domain data is a I also have another boolean flag in the UI data, telling if the input is modified once. So when this is false, I would not show the "invalid" style (it's weird to mark a whole form as invalid before the user starts to fill in it). The idea is to keep a set of domain data that's shared among UI components and elements, and control the behavior of views & controllers by UI data. Conceptually, domain data is the "real" data, and UI data is more like part of the UI element. Let's see it in action: simplescreenrecorder-2024-10-17_01.26.44.mp4 |
I've created an example in the
tutorial
directory. Here are the important bits:index.rml
:main.cpp
:The behavior:
Do we have simple solutions for these now?
One I could think of is to use an underlying data type (a String, for example) that's "large enough" to contain all input states, and scatter the validation logic to other parts of the code. But that seems to defeat the purpose of the data-binding approach.
If in the setter we can somehow tell RmlUi that the input is invalid (another approach is to bind a piece of data with a validator function), and it should not update the view, that should solve the problem too.
The text was updated successfully, but these errors were encountered: