This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from 'mson/lib/component'; | |
class MyComponent extends Component { | |
_className = 'MyComponent'; | |
_create(props) { | |
super._create(props); | |
this.set({ | |
schema: { | |
component: 'Form', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
component: 'RecordList', label: 'Contacts', | |
baseFormFactory: { | |
component: 'Factory', | |
product: { | |
component: 'Form', | |
fields: [{ name: 'fullName', component: 'PersonFullNameField' }] | |
} | |
}, | |
store: { component: 'LocalStorageStore', storeName: 'contacts' } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Move up | |
SET order = order + 1 | |
WHERE | |
order >= newOrder | |
AND order < oldOrder | |
-- Move down | |
SET order = order - 1 | |
WHERE | |
order > oldOrder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handleSubmit = () => { | |
const { form } = this.state; | |
// TODO: Contact some API with the data | |
console.log("submitting", form.getValues()); | |
// Simulate response from API saying that email address is already in use and report this error | |
// to the user | |
if (form.get("fields.email.value") === "[email protected]") { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loadValues(form) { | |
// Load any initial data, e.g. from an API | |
form.setValues({ | |
id: 'abc123', | |
firstName: "Bob", | |
lastName: "Marley", | |
email: "[email protected]" | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
componentDidMount() { | |
const form = compiler.newComponent(definition); | |
this.setState({ form }); | |
this.loadValues(form); | |
form.on("submit", this.handleSubmit); | |
form.on("reset", this.handleReset); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validators: [ | |
{ | |
where: { | |
"fields.email.value": "[email protected]" | |
}, | |
error: { | |
field: "email", | |
error: "must not be {{fields.email.value}}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ReactDOM.render( | |
<Component component={form} />, | |
document.getElementById("root") | |
); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
form.on("submit", () => alert(JSON.stringify(form.getValues()))); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const form = compiler.newComponent({ | |
component: "Form", | |
fields: [ | |
{ | |
name: "heading", | |
component: "Text", | |
text: "# Form using [MSON](https://github.com/redgeoff/mson)" | |
}, | |
{ | |
name: "fullName", |