This is a little project I created (for fun and learning purposes, even though it may not be the most optimized solution).
If you're interested, here's the link to the code: https://codepen.io/paschos/pen/xxGXMQb
I'm currently seeking assistance with the following JavaScript code:
class App extends React.Component {
validate () {
event.preventDefault();
var name = document.getElementById("documentName").value;
var email = document.getElementById("email").value;
var re = /\S+@\S+\.\S+/;
var type = document.getElementById("documentType");
var typeChosen = type.options[type.selectedIndex].value;
var category = document.getElementById("category");
var categoryChosen = category.options[category.selectedIndex].value;
if (name.length < 2 || name.length > 32) {
alert("Invalid name length.");
}
else if (typeChosen === "" || categoryChosen === "") {
alert("Please select a value from the dropdown list.");
}
else if (email.length > 128) {
alert("Email exceedes character length.")
}
else if (re.test(email) === false) {
alert("Invalid email address.");
}
}
getValue () {
return "";
}
fillBar () {
return (<progress max="100" value = {this.getValue()} id="progress">
</progress>);
}
render() {
return (
<form onSubmit = {this.validate}>
<div className = "form-progress-bar">
{this.fillBar()}
</div>
<label htmlFor="documentName">Input the document name:</label>
<br />
<input id = "documentName"
type="text"
placeholder="Document Name"
/>
<br />
<label htmlFor="documentType">Select document type:</label>
<br />
<select className = "dropdown" id = "documentType">
<option defaultValue = ""> </option>
<option value = "Plain" label = "Plain" />
<option value = "PDF" label = "PDF" />
</select>
<br />
<label htmlFor="category">Select document category:</label>
<br />
<select className = "dropdown" id = "category">
<option defaultValue > </option>
<option value = "Audit" label = "Audit" />
<option value = "Application" label="Application" />
<option value = "Other" label = "Other" />
</select>
<br />
<label htmlFor="email">Input your email address:</label>
<br />
<input id = "email"
type="text"
placeholder="Email"
/>
<br />
<button id = "button">Submit</button>
</form>
);
}
}
ReactDOM.render(
<App />,
document.getElementById('app')
);
One thing I'm struggling with is how to increment the progress value by 25 each time a field in the form is filled.
The code pen includes HTML and CSS snippets as well.
I'll greatly appreciate any kind of help!