ergobyte / qookery

Declarative UI Building for Qooxdoo
http://www.qookery.org/
Apache License 2.0
9 stars 5 forks source link

Define form model with xml #8

Open cboulanger opened 5 years ago

cboulanger commented 5 years ago

Form models are a central feature of Qookery. They can be used to populate form fields but also serve to control business logic such as visibility, enabled state etc. In order to decrease script tag noise and to enhance the visibility of this feature, I propose to add syntax that declares the initial state of the model and allows to bind the model properties to widgets and to other properties. Something like (here with a somewhat contrived example):

<model>
  <property name="editorContent" check="String" init="">
    <bind target="#saveButton" property="enabled" converter="v=>Boolean(v)" />
  </property>
  <property name="editorVisible" check="Boolean" init="true">
    <bind target="#editor" property="visibility" converter="v=>v?'visible':'excluded'"/> 
    <bind target="#saveButton" property="visibility" converter="v=>v?'visible':'excluded'"/> 
    <bind target="editorContent" converter="v=>v?'Please enter content':''"/> 
  </property>
</model>
<ace:editor id="editor" connect="editorContent" ... />
<button id="saveButton" ... />

This would do the following:

The "target" attribute in the node could differentiate between Qookery ids using the hash sign ("#rightEditor") and other properties in the model (without hash sign), making connections within the model easy. This would be handy for access control in widgets. For example, one model property determines the "enabled" status of multiple form widgets, and is, in turn, dependent on the state of another property, but needs to be converted/transformed first.

An expressive syntax like the one above would make this interdependency very readable. Maybe the converter function should therefore have access to the model, although this introduces side-effects.

cboulanger commented 4 years ago

Is this something you are considering to implement? I think it would make writing self-contained forms much easier - putting this kind of logid into script tag is ugly and error-prone...