-
a binding is just a link between a certain property on a model, and a piece of UI (FormWidget instance, <span> el, etc)
- it can be one-way (property change updates the UI) or two-way (change event from, say, and <input> el updates the model's property)
- the display value might actually be computed instead of displayed directly, the most common case of this would be showing a string value for some kind of token
-
it's convenient to group bindings, especially with forms, in which case a 'submit' event should call
.save()
on the model -
in common cases all of the binding should happen automatically -- i'm thinking like a 'data-binding' attribute that we can add to the template. common cases include:
- a simple form (whatever 'simple' means…)
- a details pane, like the ones that are so ubiquitous in daft
-
we also want something really modular -- i think we've got a lot of the pieces already, but they need to be broken out, specifically:
- a
Widgetizer
class that just takes a dom fragment and reruns a bunch of instantiatedFormWidget
's (basically breaking this into its own class) - a
BindingGroup
class that tracks the relationships between model properties and ui elements. this is a decent start. - an
ErrorPropagator
class (preferably with a name that's not stupid) that understands how to take the exception thrown byModel#validate()
and display the errors on the correctMessageList
instances. this is basicallyBoundWidgetGroup#processErrors()
, but it should also handle strings a bit more intelligently
- a
-
ultimately we just want to instantiate one view (or maybe a mixin?), but i think it should combine these pieces to make everything work
-
aBindingGroup
should be able to handle more than one model (though there should be a main/default model so we don't need to type as much) -
we need to provide easy ways to extend the validation process. this should probably happen by inheriting from the model we want and overriding
.validate()
. we also should consider async validations (like validating custom query expressions, which involves an ajax request) -- shouldModel#validate()
always return a deferred??? something that's just resolved by default in the simple case? or maybe instead of throwing an error it should just always default to the deferred? (UPDATE: the answer is yes,.validate()
always returns said deferred)
Here are our thoughts on this.
Updating a model at run time and for partial validation would mean that it will trigger update events. Other views of that model will thus change to show the current state of the model that is being edited. Not good. This may work but only if we do binding and validations on a copy of the model and then update the collections once that copy is successfully saved. But I am not sure if this is a good way to do this.
Sounds like a good idea, the getValue(), and setValue() could provide a basic functionality to format content based on a definition in strings (Locating that string could be convention based as well). We could override this if needed.
in MyBindableClass i would assume that we would have a smart implementation for the getValue() and setValue() functions which will be usable for most of the common cases and only need to be overridden if needed. The Bindings.js class should also have a way to tie the API field name with a user friendly label. There should be some translation here as well that replaces the field name as reported by the API using this binding.
We see some use for this when we are just displaying details, (but we can always have multiple binding groups rather than dealing with the complexity of multiple models in a group. For the scenario of Forms, We tried that with Action / Targetset, and there are some additional concerns on top of bindings. Like, sequence of save operations for the two models, updating model values when one model is saved and the other one needs the ID. Validation failures on server side and their handling in case of a multi model save.