Improved layout of form. Actually got data sending over a GET form method.

This commit is contained in:
wildscotsmen 2018-09-21 16:38:20 -04:00
parent cf9e4d384a
commit c22bcae00d
2 changed files with 147 additions and 86 deletions

View File

@ -1,19 +1,31 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
// import classNames from 'classnames'; import Grid from '@material-ui/core/Grid';
import { withStyles } from '@material-ui/core/styles'; import { withStyles } from '@material-ui/core/styles';
import MenuItem from '@material-ui/core/MenuItem'; import MenuItem from '@material-ui/core/MenuItem';
import TextField from '@material-ui/core/TextField'; import TextField from '@material-ui/core/TextField';
import Button from '@material-ui/core/Button';
/**
* Styles that the different
* Material UI components pull
* in. Mostly used for spacing.
*/
const styles = theme => ({ const styles = theme => ({
container: { container: {
display: 'flex', display: 'flex',
flexWrap: 'wrap', flexWrap: 'wrap',
}, },
textField: { textField: {
marginLeft: theme.spacing.unit, marginLeft: theme.spacing.unit * 2,
marginRight: theme.spacing.unit, marginRight: theme.spacing.unit,
marginTop: theme.spacing.unit, marginTop: theme.spacing.unit * 2,
flexBasis: 280,
},
button: {
marginLeft: theme.spacing.unit * 2,
marginRight: theme.spacing.unit,
marginTop: theme.spacing.unit * 2,
}, },
dense: { dense: {
marginTop: 30, marginTop: 30,
@ -23,6 +35,14 @@ const styles = theme => ({
}, },
}); });
/**
* Function for formatting the
* date as a string that
* Material UI can use. We'll
* also store the date like
* this string in the database.
* @param {*} date, Date passed in.
*/
function formatDate(date) { function formatDate(date) {
var d = new Date(date), var d = new Date(date),
month = '' + (d.getMonth() + 1), month = '' + (d.getMonth() + 1),
@ -95,29 +115,48 @@ const confidenceLevels = [
}, },
]; ];
/**
* The form compnent.
*/
class ReportForm extends React.Component { class ReportForm extends React.Component {
/**
* State of form components.
*/
state = { state = {
date: formatDate(new Date()), date: formatDate(new Date()),
time: '00:00', time: '00:00',
multiline: 'Controlled',
type: '', type: '',
confidence: '' confidence: ''
}; };
/**
* Handles state change in form
* components.
*/
handleChange = name => event => { handleChange = name => event => {
this.setState({ this.setState({
[name]: event.target.value, [name]: event.target.value,
}); });
}; };
/**
* The render method for this component.
*/
render() { render() {
const { classes } = this.props; const { classes } = this.props;
/**
* The actual form.
*/
return ( return (
<form className={classes.container} noValidate autoComplete="off"> <form className={classes.container} noValidate autoComplete="off" method='GET'>
<Grid container spacing={8}>
<Grid item xs={5} xl={2}>
<TextField <TextField
id="select-sighting-type" id="select-sighting-type"
select select
required
name="sighting-type"
label="Select" label="Select"
className={classes.textField} className={classes.textField}
value={this.state.type} value={this.state.type}
@ -128,8 +167,6 @@ class ReportForm extends React.Component {
}, },
}} }}
helperText="Please select type of sighting" helperText="Please select type of sighting"
margin="normal"
variant="outlined"
> >
{sightingTypes.map(option => ( {sightingTypes.map(option => (
<MenuItem key={option.value} value={option.value}> <MenuItem key={option.value} value={option.value}>
@ -137,10 +174,14 @@ class ReportForm extends React.Component {
</MenuItem> </MenuItem>
))} ))}
</TextField> </TextField>
</Grid>
<Grid item xs={5} xl={2}>
<TextField <TextField
id="select-confidence" id="select-confidence"
select select
required
name="sighting-confidence"
label="Select" label="Select"
className={classes.textField} className={classes.textField}
value={this.state.confidence} value={this.state.confidence}
@ -151,8 +192,6 @@ class ReportForm extends React.Component {
}, },
}} }}
helperText="Please select confidence in sighting" helperText="Please select confidence in sighting"
margin="normal"
variant="outlined"
> >
{confidenceLevels.map(option => ( {confidenceLevels.map(option => (
<MenuItem key={option.value} value={option.value}> <MenuItem key={option.value} value={option.value}>
@ -160,10 +199,14 @@ class ReportForm extends React.Component {
</MenuItem> </MenuItem>
))} ))}
</TextField> </TextField>
</Grid>
<Grid item xs={12}>
<TextField <TextField
id="sighting-date" id="sighting-date"
required
label="Sighting date" label="Sighting date"
name="sighting-date"
type="date" type="date"
value={this.state.date} value={this.state.date}
className={classes.textField} className={classes.textField}
@ -172,11 +215,16 @@ class ReportForm extends React.Component {
shrink: true, shrink: true,
}} }}
/> />
</Grid>
<Grid item xs={12}>
<TextField <TextField
id="sighting-time" id="sighting-time"
required
label="Sighting time" label="Sighting time"
name="sighting-time"
type="time" type="time"
margin="normal"
value={this.state.time} value={this.state.time}
className={classes.textField} className={classes.textField}
onChange={this.handleChange('time')} onChange={this.handleChange('time')}
@ -184,9 +232,14 @@ class ReportForm extends React.Component {
shrink: true, shrink: true,
}} }}
/> />
</Grid>
<Grid item xs={12}>
<TextField <TextField
id="sighting-description" id="sighting-description"
required
label="Description" label="Description"
name="sighting-desc"
multiline multiline
rows="5" rows="5"
placeholder="Describe the sighting to the best of your ability." placeholder="Describe the sighting to the best of your ability."
@ -198,6 +251,14 @@ class ReportForm extends React.Component {
shrink: true, shrink: true,
}} }}
/> />
</Grid>
<Grid item xs={12}>
<Button variant="contained" type="submit" color="primary" className={classes.button}>
Submit
</Button>
</Grid>
</Grid>
</form> </form>
); );
} }

View File

@ -5,7 +5,7 @@ import Typography from '@material-ui/core/Typography';
class Report extends Component { class Report extends Component {
render() { render() {
return ( return (
<Typography variant='display1' align='center' gutterBottom> <Typography variant='display1' align='left' gutterBottom>
<ReportForm/> <ReportForm/>
</Typography> </Typography>
); );