React setState object key with conditional event target - reactjs

I have a problem on setting object keys in state. So below code is a form with title, body, city and country. With the value given by user, I set them to state. But since country and city should be assign in 'address' object, I created a handler that checks if the value is country/city or not.
But turned out even if the condition is not met, and ELSE is running, still it uses the object assign in if condition.
So either it is a title or city, state is set inside the address object
Would you check where am I doing wrong?
Below is my form and handlers
class Postit extends Component {
state = {
title: "",
body: "",
address: {
country: "",
city: ""
}
};
handleChange = e => {
if (e.target.id === "country" || "city") {
let address = Object.assign({}, this.state.address);
address[e.target.id] = e.target.value;
this.setState({ address });
console.log("NewState", this.state);
} else {
console.log("Target is not city or country");
this.setState({
[e.target.id]: e.target.value
});
}
};
handleSubmit = e => {
e.preventDefault();
console.log(this.state);
};
render() {
return (
<div className="container">
<form className="white" onSubmit={this.handleSubmit}>
<h5 className="grey-text text-darken-3">Send your post</h5>
{/* Title */}
<div className="input-field">
<input type="text" id="title" onChange={this.handleChange} />
<label htmlFor="title"> Title</label>
</div>
{/* Body */}
<div className="input-field">
<textarea
id="body"
className="materialize-textarea"
onChange={this.handleChange}
/>
<label htmlFor="body"> Content</label>
</div>
{/* City / Country Select */}
<div className="input-field">
<input type="text" id="country" onChange={this.handleChange} />
<label htmlFor="country"> Write your Country</label>
</div>
<div className="input-field">
<input type="text" id="city" onChange={this.handleChange} />
<label htmlFor="city"> Write your City</label>
</div>
<div className="input-field">
<button
className="btn pink lighten-1 center-align"
style={{ marginTop: "10px", borderRadius: "6px", width: "100%" }}
>
Post it
</button>
</div>
</form>
</div>
);
}
}
Exmp, when I fill the title, The newState looks like this:
{title: "", body: "", address: {country:"", city:"", title:"test"}}
Thank you!

You're not checking the condition properly. if (e.target.id === "country" || "city") is always going to be true even if e.target.id is not "country", due to the or part where "city" is a truthy value. It should be if (e.target.id === "country" || e.target.id === "city")
handleChange = e => {
if (e.target.id === "country" || e.target.id === "city") {
let address = Object.assign({}, this.state.address);
address[e.target.id] = e.target.value;
this.setState({ address });
console.log("NewState", this.state);
} else {
console.log("Target is not city or country");
this.setState({
[e.target.id]: e.target.value
});
}
};
Hope this helps !

Related

How can I get radio button value in React?

I have three radio buttons and I need to put the value of the selected one in inputs.reply, just like I did with inputs.name, inputs.email, inputs.phone and inputs.message. How can I do this? I know it's probably a very easy thing to do, but I've been trying for hours and it doesn't work.
import Head from 'next/head'
import React, { useState } from 'react'
export default () => {
const [status, setStatus] = useState({
submitted: false,
submitting: false,
info: { error: false, msg: null }
})
const [inputs, setInputs] = useState({
reply: '',
name: '',
phone: '',
email: '',
message: ''
})
function SubmitButton(){
if (inputs.name && inputs.email && inputs.message) {
return <button type="submit" className="btn-submit" disabled={status.submitting}> {!status.submitting ? !status.submitted ? 'Submit' : 'Submitted' : 'Submitting...'} </button>
} else {
return <button type="submit" className="btn-submit" disabled>Submit</button>
};
};
const handleResponse = (status, msg) => {
if (status === 200) {
setStatus({
submitted: true,
submitting: false,
info: { error: false, msg: msg }
})
setInputs({
reply: '',
name: '',
phone: '',
email: '',
message: ''
})
} else {
setStatus({
info: { error: true, msg: msg }
})
}
}
const handleOnChange = e => {
e.persist()
setInputs(prev => ({
...prev,
[e.target.id]: e.target.value
}))
setStatus({
submitted: false,
submitting: false,
info: { error: false, msg: null }
})
}
const handleOnSubmit = async e => {
e.preventDefault()
setStatus(prevStatus => ({ ...prevStatus, submitting: true }))
const res = await fetch('/api/send', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(inputs)
})
const text = await res.text()
handleResponse(res.status, text)
}
return (
<div className="contact">
<main>
<div className="content">
<div>
<h2>Get in touch!</h2>
<h3>How can we help you?</h3>
</div>
<form onSubmit={handleOnSubmit}>
<h4>How would you like us to get back to you?</h4>
<div className="form-group form-group-radio">
<div>
<input type="radio" onChange={handleOnChange} value="Phone" name="email-reply" id="reply-phone" />
<label className="radio-label" htmlFor="reply-phone">Phone</label>
</div>
<div>
<input type="radio" onChange={handleOnChange} value="E-mail" name="email-reply" id="reply-email" />
<label className="radio-label" htmlFor="reply-email">E-mail</label>
</div>
<div>
<input type="radio" onChange={handleOnChange} value="No reply needed" name="email-reply" id="no-reply" />
<label className="radio-label" htmlFor="no-reply">No reply needed</label>
</div>
</div>
<div className="form-group">
<input
id="name"
type="text"
name="name"
onChange={handleOnChange}
required
value={inputs.name}
className={inputs.name ? "form-control active" : "form-control"}
/>
<label className="form-label" htmlFor="name">Name</label>
</div>
<div className="form-group">
<input
id="email"
type="text"
name="email"
onChange={handleOnChange}
required
value={inputs.email}
className={inputs.email ? "form-control active" : "form-control"}
/>
<label className="form-label" htmlFor="email">Email</label>
</div>
<div className="form-group">
<input
id="phone"
type="tel"
name="phone"
onChange={handleOnChange}
required
value={inputs.phone}
className={inputs.phone ? "form-control active" : "form-control"}
/>
<label className="form-label" htmlFor="phone">Phone</label>
</div>
<div className="form-group">
<textarea
id="message"
onChange={handleOnChange}
required
value={inputs.message}
className={inputs.message ? "form-control active" : "form-control"}
/>
<label className="form-label" htmlFor="message">Message</label>
</div>
<SubmitButton />
{status.info.error && (
<div className="message-feedback error">
<p>Error: {status.info.msg}</p>
</div>
)}
{!status.info.error && status.info.msg && (
<div className="message-feedback success">
<p>Thanks for messaging us!</p>
<p>We'll get back to you soon.</p>
</div>
)}
</form>
</div>
</main>
</div>
)
}
Thank you.
Remove the id attribute from all of the <input type="radio" /> and instead add a name="reply" to all of them.
Now update handleOnChange, specifically this part
setInputs(prev => ({
...prev,
[e.target.id || e.target.name]: e.target.value
}))
You can update the handleOnChange method to check for the type of the target event and if its a radio button, you can update the radio state, otherwise use the dynamic key to update the state.
const handleOnChange = (e) => {
e.persist();
const key = e.target.type === "radio" ? "reply" : e.target.id;
setInputs((prev) => ({
...prev,
[key]: e.target.value
}));
setStatus({
submitted: false,
submitting: false,
info: { error: false, msg: null }
});
};

Correct handling of Input Fields of type number in React with state

I am running into an issue where if I enter a number in the form field, and then erase it, rather than showing an empty input field it is showing the number 0. This is because of how I currently have a set state element setup to parse the input value as a number. So when the user clears the input field with backspace it is converting an empty string to a 0.
This is leading to buggy behaviour because the user won't be able to clear the field completely to type a new number and any further entry would be prefixed with the 0.
How can I fix this so it should behave correctly? Thanks
const AddWidget = () => {
const [form, setForm] = useState({ name: '', mfg: '', price: '', inStock: '' })
function handleInputChange (e) {
const { name, value } = e.target
const newForm = {
...form,
[name]: (name === 'inStock' || name === 'price') ? Number(value) : value
}
setForm(newForm)
}
function handleFormSubmit (e) {
e.preventDefault()
addWidget(form)
.then((newWidget) => {
console.log('newwidget', newWidget)
setForm({ name: '', mfg: '', price: '', inStock: '' })
return null
})
.catch(err => {
console.error(err)
})
}
return (
<div className="ui container">
<h2>Add New Widget</h2>
<form className="ui form" onSubmit={handleFormSubmit}>
<div className="field">
<label htmlFor="name">Name:</label>
<input type="text" name="name" value={form.name} onChange={handleInputChange} />
</div>
<div className="field">
<label htmlFor="mfg">Manufacturer:</label>
<input type="text" name="mfg" value={form.mfg} onChange={handleInputChange} />
</div>
<div className="field">
<label htmlFor="price">Price</label>
<input type="number" name="price" value={form.price} onChange={handleInputChange} />
</div>
<div className="field">
<label htmlFor="inStock">Stock</label>
<input type="number" name="inStock" value={form.inStock} onChange={handleInputChange} />
</div>
<button className="ui button">Add Widget</button>
</form>
</div>
)
}
I added just one more condition in your code to check if there is a value and if there isn't or the value equals false I return an empty string else your logic is applied. When I write in the field and then delete it, it stays blank which is the result you are seeking I hope.
function handleInputChange(e) {
const { name, value } = e.target;
const newForm = {
...form,
[name]: (name === 'inStock' || name === 'price') && !value ? ''
: (name === 'inStock' || name === 'price') && value ? Number(value) : value
};
setForm(newForm);
}
P.S. You can apply the same logic using if statements if you feel more comfortable with them.

react hooks: remember me checkbox in Login form not working

I have a login form functional component built using react-hooks comprising of userid, password and rememberMe checkbox.
For some reason, the checkbox is not working as in, when I click on it, it does tick or untick. Which is basically its state is not changing.
userid, password and rememberMe checkbox needs to be sent to the backend. That's why I have to couple it with inputs. If it was an independent checkbox than it would have been easy.
I have handleChange() for userid, password and I have handleChechbox() for handling checkbox.
Below is the complete code.
const Login = (props) => {
const [inputs, setInputs] = useState({
userid: "",
password: "",
rememberPassword: false,
});
const [submitted, setSubmitted] = useState(false);
const { userid, password, rememberPassword } = inputs;
// reset login status
useEffect(() => {
dispatch(loginActions.logout());
}, []);
function handleChange(e) {
const { name, value } = e.target;
setInputs((inputs) => ({ ...inputs, [name]: value }));
}
function handleChechbox(e) {
const { name, value } = e.target;
console.log("eeeeee check", e.target.type);
console.log("eeeeee check", e.target.checked);
console.log("eeeeee check inputs", inputs);
console.log("eeeeee check inputs remember", inputs.rememberPassword);
if (e.target.type === "checkbox" && !e.target.checked) {
setInputs((inputs) => ({ ...inputs, [name]: "" }));
} else {
setInputs((inputs) => ({ ...inputs, [name]: value }));
}
}
function handleSubmit(e) {
e.preventDefault();
setSubmitted(true);
if (inputs) {
// get return url from location state or default to home page
const { from } = location.state || {
from: { pathname: "/admin/summary" },
};
dispatch(loginActions.login(inputs, from));
// props.history.push("/admin/summary");
}
}
return (
<div className="Login">
<div className="login-form-container">
<div className="content">
<Form className="login-form" onSubmit={handleSubmit}>
<InputGroup>
<InputGroupAddon
className="input-group-addon"
addonType="prepend"
>
<i className="fa fa-user"></i>
</InputGroupAddon>
<input
autoFocus
type="email"
aria-label="Username"
aria-describedby="Username"
aria-invalid="false"
placeholder="Username or Email"
name="userid"
value={userid}
onChange={(event) => handleChange(event)}
className={
"form-control" + (submitted && !userid ? " is-invalid" : "")
}
/>
{submitted && !userid && (
<div className="invalid-feedback">
Username or Email is required
</div>
)}
</InputGroup>
<InputGroup>
<InputGroupAddon
className="input-group-addon"
addonType="prepend"
>
<i className="fa fa-lock"></i>
</InputGroupAddon>
<input
type="password"
name="password"
placeholder="Password"
aria-label="password"
aria-describedby="password"
value={password}
onChange={(event) => handleChange(event)}
className={
"form-control" + (submitted && !password ? " is-invalid" : "")
}
/>
{submitted && !password && (
<div className="invalid-feedback">Password is required</div>
)}
</InputGroup>
<div className="form-actions">
<br />
<div className="form-check">
<input
type="checkbox"
className="form-check-input"
id="rememberPassword"
name="checkbox"
checked={rememberPassword}
onChange={(event) => handleChechbox(event)}
// required
/>
<label className="form-check-label" for="rememberPassword">
Remember me
</label>
</div>
</div>
</Form>
</div>
</div>
</div>
);
};
You're reading the name attribute which is 'checkbox' not 'rememberPassword'. I'd imagine a simple console log of inputs would reveal you're setting the wrong property name.
Anyway your input is controlled, you don't need to read DOM values since you know that the value is and what it should change to.
function handleRememberMeChange(e) {
setInputs((inputs) => ({ ...inputs, rememberPassword: !inputs.rememberPassword }));
}
If you want it to work generically from an attribute then use id or change name to "rememberPassword". And use e.target.checked not e.target.value.
Also it's fine to do onChange={handleChechbox} instead of onChange={(event) => handleChechbox(event)} it's the same thing.

How to design State for Multiple objects using react-redux?

I need to create multiple medicine objects here. I just want to change state into array of objects. How to do that effectively? Also, want to implement controlled component for multiple medicine objects form.
Here's my component for a single medicine object:
export class MedicineForm extends Component {
state = {
medicine_name: "",
details: ""
}
static propTypes = {
postMedicine: PropTypes.func.isRequired
}
onChange = e => {
this.setState({
[e.target.name]: e.target.value
})
}
onSubmit = e => {
e.preventDefault()
const { medicine_name, details } = this.state
const medicine = { medicine_name, details }
this.props.postMedicine(medicine)
// Following code works as desired. Need to change state in this JSON Array of objects.
// this.props.postMedicine([
// {
// "id": 14,
// "medicine_name": "many5",
// "details": "sdknas"
// },
// {
// "id": 15,
// "medicine_name": "many6",
// "details": "sdknas"
// }
// ])
}
render() {
const { medicine_name, details } = this.state
return (
<Fragment>
<h1>Add Medicine</h1>
<form className="card card-body" onSubmit={this.onSubmit}>
<div className="form-row">
<div className="form-group col-md-3">
<label htmlFor="medicine_name">Medicine Name</label>
<input type="text" className="form-control" name="medicine_name" id="medicine_name" placeholder="Medicine Name" value={medicine_name} onChange={this.onChange} />
</div>
<div className="form-group col-md-3">
<label htmlFor="details">Details</label>
<input type="text" className="form-control" name="details" id="details" placeholder="Details" value={details} onChange={this.onChange} />
</div>
<div className="form-group mx-auto mt-3">
<button type="submit" className="btn btn-primary btn-lg">
Submit
</button>
</div>
</div>
</form>
</Fragment>
)
}
}
In actions, I have added following postMedicine method:
export const postMedicine = (medicine) => dispatch => {
axios.post('./api/medicine/', medicine)
.then(res => {
dispatch({
type: POST_MEDICINE,
payload: res.data
})
})
.catch(err => console.log(err))
}
//this is one row, add multiple rows as needed
state = {
medicines: [{medicine_name: "",
details: ""
}]
}
//other code
onChange = (e, i) => {
const newMedicines = this.state.medicines;
newMedicines[i] = {[e.target.name]: e.target.value, ...newMedicines[i]}
this.setState({medicines: newMedicines})
}
onSubmit = e => {
e.preventDefault()
const { medicine_name, details } = this.state
const medicine = { medicine_name, details }
this.props.postMedicine(medicine)
// Following code works as desired. Need to change state in this JSON Array of objects.
// this.props.postMedicine(this.state.medicines)
}
<form className="card card-body" onSubmit={this.onSubmit}>
{this.state.medicines.map((m, i) => (<div className="form-row">
<div className="form-group col-md-3">
<label htmlFor="medicine_name">Medicine Name</label>
<input type="text" className="form-control" name="medicine_name" id="medicine_name" placeholder="Medicine Name" value={m.medicine_name} onChange={(e) => this.onChange(e, i)} />
</div>
<div className="form-group col-md-3">
<label htmlFor="details">Details</label>
<input type="text" className="form-control" name="details" id="details" placeholder="Details" value={m.details} onChange={(e) => this.onChange(e, i)} />
</div>
<div className="form-group mx-auto mt-3">
<button type="submit" className="btn btn-primary btn-lg">
Submit
</button>
</div>
</div>))}
</form>
Form component has two parameter (aka props).
first one is item, wich determines how many form do you need.
1 form means you have group of two inputs [medicine_name,details]
2 = 4 input (2 group)
...etc
and second props is function named formHandler.
wich lifting data from child
export class MedicineForm extends Component {
state = {
medicine: [],
};
static propTypes = {
postMedicine: PropTypes.func.isRequired,
};
formHandler = (value) => {
this.setState({ medicine: value });
};
onSubmit = (e) => {
e.preventDefault();
this.props.postMedicine(this.medicine);
};
render() {
return (
<>
<h1>Add Medicine</h1>
{JSON.stringify(this.state.medicine)}
<form className="card card-body" onSubmit={this.onSubmit}>
<Form item="4" formHandler={this.formHandler} />
<div className="form-group mx-auto mt-3">
<button type="submit" className="btn btn-primary btn-lg">
Submit
</button>
</div>
</form>
</>
);
}
}
Form Component
class Form extends Component {
constructor(props) {
super(props);
}
state = {
medicine: [...Array(+this.props.item)].map((_, idx) => ({
id: idx + 1,
medicine_name: "",
details: "",
})),
};
static propTypes = {
item: PropTypes.string,
formHandler: PropTypes.func,
};
onChange = ({ target: { id, name, value } }) => {
this.setState((prevState) => {
const medicine = prevState.medicine.map((item) =>
item.id === Number(id) ? { ...item, [name]: value } : item
);
this.props.formHandler(
medicine.filter((item) => item["medicine_name"] || item["details"])
);
return {
medicine,
};
});
};
render() {
return (
<div className="form-row">
{this.state.medicine.map((item, id) => (
<div key={item.id}>
<div className="form-group col-md-3">
<label htmlFor="medicine_name">Medicine Name</label>
<input
type="text"
className="form-control"
name="medicine_name"
id={item.id}
value={item.medicine_name}
placeholder="Medicine Name"
onChange={this.onChange}
/>
</div>
<div className="form-group col-md-3">
<label htmlFor="details">Details</label>
<input
type="text"
className="form-control"
name="details"
id={item.id}
value={item.details}
placeholder="Details"
onChange={this.onChange}
/>
</div>
</div>
))}
</div>
);
}
}
there is check if object has some value then lifting data.
you can change logic optional
medicine.filter((item) => item["medicine_name"] || item["details"])
You could do something like this in redux store:
[
{ id: 1, medicineName: '', details: '' },
{ id: 2, medicineName: '', details: '' },
...
]
And to make your input fields controlled just handle the state in the component.

Storing data in multiple tables in react on the basis of role

I'm new to react and i'm building a website in which user is added on the basis of role. While adding user information, user selects a role in drop down. I have a table for Role in which only roles are kept(admin, teacher and team lead), a User table which contains user information( name, email password, etc) and a UserRole table which will have a userID and a roleID to represent which role is assigned to which user. I'm using asp.net core web-API to get and post data.
I just can't figure that out how to save roleID against the role that has been selected and userID of user in UserRole table.
can please someone help me with it?
Here is my react code of file Adduser.tsx
import * as React from 'react';
//import { ReactComponent } from '*.svg';
import '../css/form.css';
import Sidebar from '../Component/sidebar/sidebar';
const axios = require('axios');
class Adduser extends React.Component<any, any> {
constructor(props: any) {
super(props);
this.state = {
teacherId: 0,
name: '',
email: '',
password: '',
confirmPassword: '',
gender: '',
question: [],
nameError: '',
passError: '',
emailError: ''
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
this.handlePasswordChange = this.handlePasswordChange.bind(this);
}
componentWillMount() {
if (this.props.match.params.id != undefined) {
axios.get('https://localhost:44310/api/Users/' + this.props.match.params.id)
.then((response: any) => {
this.setState({
teacherId: response.data.teacherId,
name: response.data.name,
email: response.data.email,
password: response.data.password,
confirmPassword: response.data.confirmPassword,
gender: response.data.gender,
role: response.data.role,
question: []
});
})
.catch((error: any) => {
console.log(error);
});
}
}
handleChange = (event: any) => {
this.setState({ [event.target.name]: event.target.value }, () => this.validateName())
}
handlePasswordChange = (event: any) => {
this.setState({ [event.target.name]: event.target.value }, () => this.validatePassword())
}
validateName() {
const { name } = this.state;
this.setState(
{ nameError: name.length > 3 ? null : 'Name must contain atleast 3 characters' }
// passError: password.length > 3 || password ? null : 'Password must contain atleast 6 characters'}
)
}
validatePassword() {
const { password } = this.state;
this.setState({
passError: password.length > 6 ? null : 'Password must contain atleast 6 characters'
}
)
}
validateEmail(email: any) {
const pattern = /[a-zA-Z0-9]+[\.]?([a-zA-Z0-9]+)?[\#][a-z]{3,9}[\.][a-z]{2,5}/;
const result = pattern.test(email);
if (result === true) {
this.setState({
emailError: false,
email: email
})
} else {
this.setState({
emailError: true
})
}
// email = $('email');
// var filter = /^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
// if (filter.test(email.value)) {
// // Yay! valid
// return '';
// }
// else
// return 'invalid email';
}
handleSubmit(event: any) {
event.preventDefault();
if (this.props.match.params.id != undefined) {
const { password, confirmPassword } = this.state
if (password !== confirmPassword) {
alert('passwords do not match')
}
else {
axios.put(`https://localhost:44310/api/Users/${this.props.match.params.id}`, this.state)
.then((response: any) => {
this.props.history.push('/');
})
.catch(function (error: any) {
console.log(error);
});
}
} else {
const { password, confirmPassword, name } = this.state
if (password !== confirmPassword) {
alert('passwords do not match')
}
else {
axios.post('https://localhost:44310/api/Users/', this.state)
.then((response: any) => {
console.log(response);
alert('User has been added successfully')
})
.catch(function (error: any) {
console.log(error);
alert('Sorry! Your request can not be processed at the moment')
});
}
}
}
render() {
return (
<div className="row">
<div className=" col-lg-2">
<Sidebar />
</div>
<div className="col-lg-10">
<div className="content" >
<div className="container-fluid">
<div className="row" >
<div className="col-lg-3"> </div>
<div className="col-lg-6" style={{ paddingTop: "30px" }}>
<div id="ui">
{this.props.match.params.id != undefined ? <h1 style={{ marginTop: "15px" }}>EDIT ACCOUNT</h1> : <h1 style={{ marginTop: "15px" }}>ADD ACCOUNT</h1>}
<form className="form-group" method="post" onSubmit={this.handleSubmit} autoComplete="off">
<label> Name:</label>
<div className="name">
<input type="text"
onChange={this.handleChange}
name="name"
value={this.state.name}
className={`form-control ${this.state.nameError ? 'is-invalid' : ''}`}
placeholder="Enter username " required
onBlur={this.validateName.bind(this)} />
<div className="invalid-feedback">Name must be longer than 3 characters</div>
</div>
<br />
<label> Email:</label>
<div className="mail">
<input type="email" name="email" value={this.state.email} onChange={this.handleChange} className="form-control" placeholder="Enter E-mail" required />
<div className="invalid-feedback">Email is invalid</div>
</div>
<br />
<div className="row">
<div className="col-lg-6">
<label> Password:</label>
<div className="pass">
<input type="password" name="password" value={this.state.password} onChange={this.handlePasswordChange} className={`form-control ${this.state.passError ? 'is-invalid' : ''}`} id="pwd" placeholder="Enter password" required onBlur={this.validatePassword.bind(this)} />
<div className="invalid-feedback">Password must be longer than 6 characters</div>
</div>
</div>
<div className="col-lg-6">
<label> Re-type Password:</label>
<div className="pass1">
<input type="password" name="confirmPassword" value={this.state.pass1} onChange={this.handleChange} className="form-control" id="pwd1" placeholder="Re-type password" required />
</div>
</div>
<br />
<div className="col-lg-12">
<select className="form-control" name="gender" value={this.state.gender} onChange={this.handleChange} id="sel" style={{ marginTop: "35px" }} required>
<option>Choose Gender</option>
<option>Male</option>
<option>Female</option>
</select>
</div>
<br />
<div className="col-lg-12">
<select className="form-control" name="role" value={this.state.role} onChange={this.handleChange} id="sel" style={{ marginTop: "35px" }} required>
<option>Role</option>
<option>Admin</option>
<option>Teacher</option>
<option>TeamLead</option>
</select>
</div>
<br />
<div className="col-lg-12">
{/* <Link className="nav-link" to="/"> */}
<input type="submit" name="submit" value="submit" className="btn btn-primary btn-block btn-lg" style={{ marginTop: "20px" }} />
{/* </Link> */}
</div>
</div>
</form>
</div>
</div>
<div className="col-lg-3"></div>
</div>
</div>
</div>
</div>
</div>
);
}
}
export default Adduser;

Resources