-function CategoryRequest(props) {
- return (
- <div className="category-request">
- <h2>Submit a Category</h2>
- <p>
+class CategoryRequest extends React.Component {
+ constructor(props) {
+ super(props);
+ this.category = React.createRef();
+
+ this.handle_change = this.handle_change.bind(this);
+ this.handle_submit = this.handle_submit.bind(this);
+ }
+
+ handle_change(event) {
+ const category_input = this.category.current;
+ const category = category_input.value;
+
+ if (/[0-9]/.test(category))
+ category_input.setCustomValidity("");
+ }
+
+ handle_submit(event) {
+ const category_input = this.category.current;
+ const category = category_input.value;
+
+ /* Prevent the default page-changing form-submission behavior. */
+ event.preventDefault();
+
+ if (! /[0-9]/.test(category)) {
+ category_input.setCustomValidity("Category must include a number");
+ event.currentTarget.reportValidity();
+ return;
+ }
+
+ console.log("Do something here with category: " + category);
+ }
+
+ render() {
+ return (
+ <div className="category-request">
+ <h2>Submit a Category</h2>
+ <p>