Skip to content
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

Define form model with xml #8

Open
cboulanger opened this issue Feb 28, 2019 · 1 comment
Open

Define form model with xml #8

cboulanger opened this issue Feb 28, 2019 · 1 comment

Comments

@cboulanger
Copy link
Contributor

cboulanger commented Feb 28, 2019

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:

  • It would initialize two model properties, editorContent (String) and editorVisible(Boolean)
  • It would enable or disable the "Save" button dependent on whether the editor contains text
  • It would show or hide the editor and the button dependent on whether the editorVisible model property is true
  • It would set the content of the editor dependent on the change of the editorVisible property (this doesn't make much sense, just as an example)

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants