Skip to content

Instantly share code, notes, and snippets.

@zindel
Created February 3, 2016 12:30
Show Gist options
  • Save zindel/e1a429ba4eca54fffd9a to your computer and use it in GitHub Desktop.
Save zindel/e1a429ba4eca54fffd9a to your computer and use it in GitHub Desktop.
import React from 'react';
import {Preloader} from 'rex-widget/ui';
import {Fetch} from 'rex-widget/data';
import * as forms from 'rex-widget/form';
@Fetch(function fetchGreeting(propsAndDataParams) {
let {data, id} = propsAndDataParams;
return {
data: data.params({'user:id': id}).getSingleEntity(),
}
})
export default class SimpleForm extends React.Component {
render() {
let {data} = this.props.fetched;
// uses JSON schema. See http://json-schema.org/
let schema = {
type: 'object',
required: ['name'],
properties: {
name: {type: 'string'},
is_expired: {type: 'boolean'}
}
};
return (
<div>
{data.updating ? <Preloader/> :
<form.EntityForm
entity="user"
schema="schema"
value={data}
submitTo={this.props.data}
>
Name: <form.Field selectFormValue="name"/>
Expired?: <form.CheckboxField selectFormValue="is_expired"/>
</form.EntityForm>
}
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment